﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using cszmcaux;
using SSVisionCom;
using Newtonsoft.Json;
using HalconDotNet;
using MvCamCtrl.NET;
using System.Net.Sockets;
using App_Onnx;
using OpenCvSharp;
using S7.Net;
using OpenCvSharp.XImgProc;
using System.Windows.Forms.DataVisualization.Charting;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Win32;



namespace CMT
{
    public partial class Form1 : Form
    {
        public AutoZone autoZone = new AutoZone();
        public IntPtr Phandle;
        public AxisParameter axisParameter = new AxisParameter();
        public Config configFile = new Config();
        public bool SystemRunState = true;
        public bool continuousImage = false;
        public bool autoRunMode = false;
        public bool autoState = false;
        public bool Station_RunLeft = false;
        public bool Station_RunRight = false;
        public bool Station_RunLeftNet = false;
        public bool Station_RunRightNet = false;
        public bool IRCode_InputMode_Left = false;
        public bool IRCode_InputMode_Right = false;
        public bool Shield_ScreenTest = false;
        public bool Shield_KeyTest = false;
        public bool KeyDown_Left = false;
        public bool KeyDown_Right = false;


        public float homex { get; set; }
        public float homey { get; set; }
        public float homez { get; set; }
        public float offsx { get; set; }
        public float offsy { get; set; }
        public float offsz { get; set; }

        string a;
        public int LeftCodeNumber = 0;
        public int LeftCodeNumber1 = 0;
        public int LeftCodeNumber2 = 0;
        public int LeftCodeNumber3 = 0;
        public int RightCodeNumber = 0;
        public int RightCodeNumber1 = 0;
        public int RightCodeNumber2 = 0;
        public int RightCodeNumber3 = 0;
        public Bitmap ManualGetImage = null;
        public bool SavaImage = false;
        public int SaveNG_ScreenCount = 0;
        public List<Bitmap> Image_Screen_Left = new List<Bitmap>();
        public List<Bitmap> Image_Screen_Right = new List<Bitmap>();
        public List<Bitmap> Image_Key_Left = new List<Bitmap>();
        public List<Bitmap> Image_Key_Right = new List<Bitmap>();
        public Motioncontrol motioncontrol_Left = new Motioncontrol();
        public Motioncontrol motioncontrol_Right = new Motioncontrol();
        public CheckBox[] InputList_Control;
        public CheckBox[] OutputList_Control_IOCard;
        public CheckBox[] OutputList_Control_PCICard;
        public TestResult TestReslt = new TestResult();
        public MotionPoint MotionPoint_Left = new MotionPoint();
        public MotionPoint MotionPoint_Right = new MotionPoint();
        public string Code_Station_Left = "";
        public string Code_Station_Right = "";
        public YKQFeature ykqFeature = new YKQFeature();
        public List<string> TestBoard_Left_msgList = new List<string>();
        public List<string> TestBoard_Right_msgList = new List<string>();
        public List<IRTestInfo> SP_infoList_Left = new List<IRTestInfo>();
        public List<IRTestInfo> SP_infoList_Right = new List<IRTestInfo>();
        public Algorithm algorithm = new Algorithm();
        public HikVisionCamera Camera1 = new HikVisionCamera();
        public HikVisionCamera Camera2 = new HikVisionCamera();
        public HikVisionCamera Camera3 = new HikVisionCamera();
        public HikVisionCamera Camera4 = new HikVisionCamera();
        public HikVisionCamera Camera5 = new HikVisionCamera();
        public HikVisionCamera Camera6 = new HikVisionCamera();
        public HikVisionCamera Camera7 = new HikVisionCamera();
        public HikVisionCamera Camera8 = new HikVisionCamera();
        public ProductManager ProductTotal = new ProductManager(Directory.GetCurrentDirectory() + @"\ProductTotal.ini");
        public Task GetImage_task_Left;
        public Task GetImage_task_Right;
        public Task IOStatus_Task;
        public Task AxisState_task;
        public Thread Station_Left_Task;
        public Thread Station_Right_Task;
        public Plc PLC;
        public bool PLCState = false;
        public HDrawingObject DraROI;
        public HObject ModelImage;
        public HObject KeyImage;

        public uint Empty_Left = 0;
        public uint Empty_Right = 0;

        public HObject Manual_YJImage = new HObject();
        public HObject Manual_YJImage_Em = new HObject();
        public TcpNet NetServer = new TcpNet();
        public bool isNewInfercesMode = false;
        public Inference_onnx inference_Onnx;
        public Inference_onnx ScreenClass;
        public int NowProductID = 0;
        public HTuple KeyHomat_Left;
        public HTuple KeyHomat_Right;
        public TcpNet TestBoard_Left = new TcpNet();
        public TcpNet TestBoard_Right = new TcpNet();
        public uint Scram = 0;
        public List<YKQ_Test> TestList = new List<YKQ_Test>();
        public List<HSmartWindowControl> TestWindow_Left = new List<HSmartWindowControl>();
        public List<HSmartWindowControl> TestWindow_Right = new List<HSmartWindowControl>();
        private int NowPoit_Location_Left = 0;
        private int NowPoit_Location_Right = 0;
        public bool TestBoard_AutoRun_Left = false;
        public bool TestBoard_AutoRun_Right = false;

        public string NowMotionControl = "";
        public string NowScreenModel = "";
        public string NowKeyModel = "";

        public Form1()
        {
            InitializeComponent();
            this.hSmartWindowControl9.MouseWheel += HSmartWindowControl9_MouseWheel;
            autoZone.TheHeight = this.Height;
            autoZone.TheWidth = this.Width;
            autoZone.setTag(this);
            InputList_Control = new CheckBox[] { INPUT0, INPUT1, INPUT2, INPUT3, INPUT4, INPUT5, INPUT6, INPUT7, INPUT8, INPUT9, INPUT10, INPUT11, INPUT12, INPUT13, INPUT14, INPUT15 };
            OutputList_Control_IOCard = new CheckBox[] { OUTPUT0, OUTPUT1, OUTPUT2, OUTPUT3, OUTPUT4, OUTPUT5, OUTPUT6, OUTPUT7, OUTPUT8, OUTPUT9, OUTPUT10, OUTPUT11, OUTPUT12, OUTPUT13, OUTPUT14, OUTPUT15 };
            OutputList_Control_PCICard = new CheckBox[] { OUTPUT16, OUTPUT17, OUTPUT18, OUTPUT19, OUTPUT20, OUTPUT21, OUTPUT22, OUTPUT23, OUTPUT24, OUTPUT25, OUTPUT26, OUTPUT27, OUTPUT28, OUTPUT29, OUTPUT30, OUTPUT31 };
            NetServer.SetMsgHandle(ProcessMsg);
            NetServer.Start(5000);
        }

        private void HSmartWindowControl9_MouseWheel(object sender, MouseEventArgs e)
        {
            //HSmartWindowControl控件的区域
            Rectangle rect = hSmartWindowControl9.RectangleToScreen(hSmartWindowControl9.ClientRectangle);
            //滚动时，鼠标悬停在在HSmartWindowControl控件上
            if (rect.Contains(System.Windows.Forms.Cursor.Position))
            {
                //缩放
                hSmartWindowControl9.HSmartWindowControl_MouseWheel(sender, e);
            }
        }

        private void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            //HSmartWindowControl控件的区域
            Rectangle rect = hSmartWindowControl9.RectangleToScreen(hSmartWindowControl9.ClientRectangle);
            //滚动时，鼠标悬停在在HSmartWindowControl控件上
            if (rect.Contains(System.Windows.Forms.Cursor.Position))
            {
                //缩放
                hSmartWindowControl9.HSmartWindowControl_MouseWheel(sender, e);
            }
        }

        private int FindProductID(string ProductMode, Config ConfigFile)
        {
            int Result = 0;
            for (int i = 0; i < configFile.productList.Count; i++)
            {
                if (ProductMode == configFile.productList[i].Model)
                {
                    Result = i;
                    break;
                }
            }

            return Result;
        }

        private void ProcessMsg(string Ip, string msg)
        {
            if (msg != "")
            {
                switch (msg)
                {
                    case "StartL":

                        if (Station_RunLeftNet == false) Station_RunLeftNet = true;


                        break;
                    case "StartR":
                        if (Station_RunRightNet == false) Station_RunRightNet = true;



                        break;
                    default:
                        break;
                }
            }
        }

        private void KeyDisp(HSmartWindowControl hSmartWindow, string fileName)
        {
            HOperatorSet.ClearWindow(hSmartWindow.HalconWindow);
            HOperatorSet.ReadImage(out HObject LocalImg, fileName);
            HOperatorSet.GetImageSize(LocalImg, out HTuple imgWidth, out HTuple imgHeigh);
            HOperatorSet.SetPart(hSmartWindow.HalconWindow, 0, 0, imgHeigh - 1, imgWidth - 1);
            HOperatorSet.DispObj(LocalImg, hSmartWindow.HalconWindow);

        }
        private void ConnectMotionControl()
        {
            try
            {
                int ret = zmcaux.ZAux_FastOpen(configFile.MotionControl, "Pci1", 1000, out Phandle);
                motioncontrol_Left.Phandle = Phandle;
                if (ret == 0)
                {
                    toolStripStatusLabel2.Text = "已连接";
                    toolStripStatusLabel2.BackColor = Color.Green;
                }
                else
                {
                    toolStripStatusLabel2.Text = "未连接";
                    MessageBox.Show("运动控制卡未连接，请重启电脑");
                    toolStripStatusLabel2.BackColor = Color.Red;
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
                SystemRunState = false;
            }
        }

        private void InitPLC()
        {
            if (configFile.PLC_Start == true)
            {
                PLC = new Plc(CpuType.S71500, configFile.PLCIP, 0, 1);
                try
                {
                    PLC.Open();
                    PLCState = true;
                    Task.Run((Action)PLC_Run);
                    if (PLC.IsConnected == true)
                    {
                        toolStripStatusLabel6.Text = "已连接";
                        toolStripStatusLabel6.BackColor = Color.Green;
                    }
                    else
                    {
                        toolStripStatusLabel6.Text = "未连接";
                        toolStripStatusLabel6.BackColor = Color.Red;
                    }

                }
                catch (Exception ex)
                {
                    PLCState = false;
                    MessageBox.Show("PLC连接访问异常，连接失败！具体原因：" + ex.Message, "连接提示");
                }
            }
        }
        private void PLC_Run()
        {

            float lefthomepointx = 0;
            float lefthomepointy = 0;
            float righthomepointx = 0;
            float righthomepointy = 0;


            while (PLCState)
            {
                zmcaux.ZAux_Direct_GetIn(Phandle, 64 + 8, ref Empty_Left);
                lefthomepointx = configFile.LeftHomeX - axisParameter.Axis1Mpos;
                lefthomepointy = configFile.LeftHomeY - axisParameter.Axis2Mpos;
                righthomepointx = configFile.RightHomeX - axisParameter.Axis3Mpos;
                righthomepointy = configFile.RightHomeY - axisParameter.Axis4Mpos;
                if (Empty_Left == 1 || Station_RunLeft == true || Math.Abs(lefthomepointx) > 10 || Math.Abs(lefthomepointx) < -10 || (Math.Abs(lefthomepointy) > 10 || Math.Abs(lefthomepointy) < -10) || Scram == 0)
                {
                    PLC.Write(configFile.PLC_address.GetMateriel_Left, false);
                }
                else
                {
                    PLC.Write(configFile.PLC_address.GetMateriel_Left, true);
                    PLC.Write(configFile.PLC_address.TestComplete_Left, false);
                    toolStripStatusLabel10.Text = "左要料";
                }

                //转发有料感应信号给PLC
                if (configFile.PLC_address.Left_StationIsEmpty != "")
                {
                    if (Empty_Left == 1)
                    {
                        PLC.Write(configFile.PLC_address.Left_StationIsEmpty, true);
                    }
                    else
                    {
                        PLC.Write(configFile.PLC_address.Left_StationIsEmpty, false);
                    }
                }

                zmcaux.ZAux_Direct_GetIn(Phandle, 64 + 9, ref Empty_Right);
                if (Empty_Right == 1 || Station_RunRight == true || Math.Abs(righthomepointx) > 10 || Math.Abs(righthomepointx) < -10 || (Math.Abs(righthomepointy) > 10 || Math.Abs(righthomepointy) < -10) || Scram == 0)
                {
                    PLC.Write(configFile.PLC_address.GetMateriel_Right, false);

                }
                else
                {
                    PLC.Write(configFile.PLC_address.GetMateriel_Right, true);
                    PLC.Write(configFile.PLC_address.TestComplete_Right, false);
                    toolStripStatusLabel12.Text = "右要料";
                }

                //转发有料感应信号给PLC
                if (configFile.PLC_address.Right_StationIsEmpty != "")
                {
                    if (Empty_Right == 1)
                    {
                        PLC.Write(configFile.PLC_address.Right_StationIsEmpty, true);
                    }
                    else
                    {
                        PLC.Write(configFile.PLC_address.Right_StationIsEmpty, false);
                    }
                }

                Thread.Sleep(500);
            }
        }

        private void ApplyAxisParameter(AxisParameter axisParameter)
        {

            try
            {
                //轴1
                zmcaux.ZAux_Direct_SetSpeed(Phandle, 0, axisParameter.Axis1Speed);
                zmcaux.ZAux_Direct_SetUnits(Phandle, 0, axisParameter.Axis1Units);
                zmcaux.ZAux_Direct_SetAccel(Phandle, 0, axisParameter.Axis1Accel);
                zmcaux.ZAux_Direct_SetDecel(Phandle, 0, axisParameter.Axis1Decel);

                //轴2
                zmcaux.ZAux_Direct_SetSpeed(Phandle, 1, axisParameter.Axis2Speed);
                zmcaux.ZAux_Direct_SetUnits(Phandle, 1, axisParameter.Axis2Units);
                zmcaux.ZAux_Direct_SetAccel(Phandle, 1, axisParameter.Axis2Accel);
                zmcaux.ZAux_Direct_SetDecel(Phandle, 1, axisParameter.Axis2Decel);

                //轴3
                zmcaux.ZAux_Direct_SetSpeed(Phandle, 2, axisParameter.Axis3Speed);
                zmcaux.ZAux_Direct_SetUnits(Phandle, 2, axisParameter.Axis3Units);
                zmcaux.ZAux_Direct_SetAccel(Phandle, 2, axisParameter.Axis3Accel);
                zmcaux.ZAux_Direct_SetDecel(Phandle, 2, axisParameter.Axis3Decel);

                //轴4
                zmcaux.ZAux_Direct_SetSpeed(Phandle, 3, axisParameter.Axis4Speed);
                zmcaux.ZAux_Direct_SetUnits(Phandle, 3, axisParameter.Axis4Units);
                zmcaux.ZAux_Direct_SetAccel(Phandle, 3, axisParameter.Axis4Accel);
                zmcaux.ZAux_Direct_SetDecel(Phandle, 3, axisParameter.Axis4Decel);

                //轴5
                zmcaux.ZAux_Direct_SetSpeed(Phandle, 4, axisParameter.Axis5Speed);
                zmcaux.ZAux_Direct_SetUnits(Phandle, 4, axisParameter.Axis5Units);
                zmcaux.ZAux_Direct_SetAccel(Phandle, 4, axisParameter.Axis5Accel);
                zmcaux.ZAux_Direct_SetDecel(Phandle, 4, axisParameter.Axis5Decel);

                //轴6
                zmcaux.ZAux_Direct_SetSpeed(Phandle, 5, axisParameter.Axis6Speed);
                zmcaux.ZAux_Direct_SetUnits(Phandle, 5, axisParameter.Axis6Units);
                zmcaux.ZAux_Direct_SetAccel(Phandle, 5, axisParameter.Axis6Accel);
                zmcaux.ZAux_Direct_SetDecel(Phandle, 5, axisParameter.Axis6Decel);
            }

            catch
            {
                MessageBox.Show("写入轴参数异常");
            }

        }
        private void InitListView_PointList(ListView listView)
        {

            ColumnHeader columnHeader5 = new ColumnHeader();
            columnHeader5.Text = "动作名称";
            columnHeader5.TextAlign = HorizontalAlignment.Center;
            columnHeader5.Width = Convert.ToInt16(listView.Width * 0.15);


            ColumnHeader columnHeader6 = new ColumnHeader();
            columnHeader6.Text = "动作类型";
            columnHeader6.TextAlign = HorizontalAlignment.Center;
            columnHeader6.Width = Convert.ToInt16(listView.Width * 0.15);

            ColumnHeader columnHeader7 = new ColumnHeader();
            columnHeader7.Text = "工业码值";
            columnHeader7.TextAlign = HorizontalAlignment.Center;
            columnHeader7.Width = Convert.ToInt16(listView.Width * 0.10);

            ColumnHeader columnHeader1 = new ColumnHeader();
            columnHeader1.Text = "坐标X";
            columnHeader1.TextAlign = HorizontalAlignment.Center;
            columnHeader1.Width = Convert.ToInt16(listView.Width * 0.15);


            ColumnHeader columnHeader2 = new ColumnHeader();
            columnHeader2.Text = "坐标Y";
            columnHeader2.TextAlign = HorizontalAlignment.Center;
            columnHeader2.Width = Convert.ToInt16(listView.Width * 0.15);


            ColumnHeader columnHeader3 = new ColumnHeader();
            columnHeader3.Text = "坐标Z_高位";
            columnHeader3.TextAlign = HorizontalAlignment.Center;
            columnHeader3.Width = Convert.ToInt16(listView.Width * 0.15);

            ColumnHeader columnHeader4 = new ColumnHeader();
            columnHeader4.Text = "坐标Z_低位";
            columnHeader4.TextAlign = HorizontalAlignment.Center;
            columnHeader4.Width = Convert.ToInt16(listView.Width * 0.15);

            listView.GridLines = true;
            listView.Scrollable = true;
            listView.FullRowSelect = true;
            listView.MultiSelect = false;
            listView.View = View.Details;
            listView.Columns.Add(columnHeader5);
            listView.Columns.Add(columnHeader6);
            listView.Columns.Add(columnHeader7);
            listView.Columns.Add(columnHeader1);
            listView.Columns.Add(columnHeader2);
            listView.Columns.Add(columnHeader3);
            listView.Columns.Add(columnHeader4);
        }
        private void InitListView_HomePage(ListView listView)
        {
            listView.GridLines = true;
            listView.Scrollable = true;
            listView.FullRowSelect = true;
            listView.MultiSelect = false;
            listView.View = View.Details;
            ColumnHeader columnHeader1 = new ColumnHeader();
            columnHeader1.Text = "测试项目";
            columnHeader1.TextAlign = HorizontalAlignment.Center;
            columnHeader1.Width = Convert.ToInt16(listView.Width * 0.5);

            ColumnHeader columnHeader2 = new ColumnHeader();
            columnHeader2.Text = "当前测量值";
            columnHeader2.TextAlign = HorizontalAlignment.Center;
            columnHeader2.Width = Convert.ToInt16(listView.Width * 0.5);

            listView.Columns.Add(columnHeader1);
            listView.Columns.Add(columnHeader2);

            ListViewItem listViewItem1 = new ListViewItem();
            listViewItem1.Text = "发光强度";
            listViewItem1.SubItems.Add("0");

            ListViewItem listViewItem2 = new ListViewItem();
            listViewItem2.Text = "动态电流";
            listViewItem2.SubItems.Add("0.000mA");

            ListViewItem listViewItem3 = new ListViewItem();
            listViewItem3.Text = "静态电流";
            listViewItem3.SubItems.Add("0.000uA");

            ListViewItem listViewItem4 = new ListViewItem();
            listViewItem4.Text = "载波频率";
            listViewItem4.SubItems.Add("0000KHz");

            ListViewItem listViewItem5 = new ListViewItem();
            listViewItem5.Text = "屏幕测试";
            listViewItem5.SubItems.Add("待测试");

            ListViewItem listViewItem6 = new ListViewItem();
            listViewItem6.Text = "按键测试";
            listViewItem6.SubItems.Add("待测试");



            listView.Items.Add(listViewItem1);
            listView.Items.Add(listViewItem2);
            listView.Items.Add(listViewItem3);
            listView.Items.Add(listViewItem4);
            listView.Items.Add(listViewItem5);
            listView.Items.Add(listViewItem6);



        }
        private void InitListView_IRList(ListView listView)
        {
            listView.GridLines = true;
            listView.Scrollable = true;
            listView.FullRowSelect = true;
            listView.MultiSelect = false;
            listView.View = View.Details;
            ColumnHeader columnHeader1 = new ColumnHeader();
            columnHeader1.Text = "按键名称";
            columnHeader1.TextAlign = HorizontalAlignment.Center;
            columnHeader1.Width = Convert.ToInt16(listView.Width * 0.1);

            ColumnHeader columnHeader2 = new ColumnHeader();
            columnHeader2.Text = "按键名称";
            columnHeader2.TextAlign = HorizontalAlignment.Center;
            columnHeader2.Width = Convert.ToInt16(listView.Width * 0.9);

            listView.Columns.Add(columnHeader1);
            listView.Columns.Add(columnHeader2);

        }
        private void SaveAxisParameter()
        {
            try
            {
                SaveDataToTxtBox(textBox1, ref axisParameter.Axis1Speed);
                SaveDataToTxtBox(textBox2, ref axisParameter.Axis1Units);
                SaveDataToTxtBox(textBox3, ref axisParameter.Axis1Accel);
                SaveDataToTxtBox(textBox4, ref axisParameter.Axis1Decel);

                SaveDataToTxtBox(textBox8, ref axisParameter.Axis2Speed);
                SaveDataToTxtBox(textBox6, ref axisParameter.Axis2Units);
                SaveDataToTxtBox(textBox7, ref axisParameter.Axis2Accel);
                SaveDataToTxtBox(textBox5, ref axisParameter.Axis2Decel);

                SaveDataToTxtBox(textBox12, ref axisParameter.Axis5Speed);
                SaveDataToTxtBox(textBox10, ref axisParameter.Axis5Units);
                SaveDataToTxtBox(textBox11, ref axisParameter.Axis5Accel);
                SaveDataToTxtBox(textBox9, ref axisParameter.Axis5Decel);


                SaveDataToTxtBox(textBox24, ref axisParameter.Axis3Speed);
                SaveDataToTxtBox(textBox22, ref axisParameter.Axis3Units);
                SaveDataToTxtBox(textBox23, ref axisParameter.Axis3Accel);
                SaveDataToTxtBox(textBox21, ref axisParameter.Axis3Decel);

                SaveDataToTxtBox(textBox20, ref axisParameter.Axis4Speed);
                SaveDataToTxtBox(textBox18, ref axisParameter.Axis4Units);
                SaveDataToTxtBox(textBox19, ref axisParameter.Axis4Accel);
                SaveDataToTxtBox(textBox17, ref axisParameter.Axis4Decel);

                SaveDataToTxtBox(textBox16, ref axisParameter.Axis6Speed);
                SaveDataToTxtBox(textBox14, ref axisParameter.Axis6Units);
                SaveDataToTxtBox(textBox15, ref axisParameter.Axis6Accel);
                SaveDataToTxtBox(textBox13, ref axisParameter.Axis6Decel);

                SaveDataToTxtBox(textBox53, ref axisParameter.Station_Left_SafetyHight);
                SaveDataToTxtBox(textBox56, ref axisParameter.Station_Left_Zoffset);
                SaveDataToTxtBox(textBox55, ref axisParameter.Station_Right_SafetyHight);
                SaveDataToTxtBox(textBox54, ref axisParameter.Station_Right_Zoffset);
            }
            catch
            {
                MessageBox.Show("写入轴参数异常");
            }
        }
        private void InitSerialPort()
        {
            TestBoard_Left.SetMsgHandle(LeftTestBoard_ProcessMsg);
            TestBoard_Left.Start(2880);

            if (TestBoard_Left.Connect(configFile.TestBoard_Left_PortName, 500) == true) TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Set_Limit:4000:4800:400:800:1200:2000");
            TestBoard_Right.SetMsgHandle(RightTestBoard_ProcessMsg);
            TestBoard_Right.Start(2881);
            if (TestBoard_Right.Connect(configFile.TestBoard_Right_PortName, 500) == true) TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Set_Limit:4000:4800:400:800:1200:2000");

        }

        private void LeftTestBoard_ProcessMsg(string ip, string msg)
        {
           
            if (ip == configFile.TestBoard_Left_PortName)
            {
                string[] ResolveStr = Resolve(msg.Replace("\n", ""));
                for (int j = 0; j < ResolveStr.Length; j++)
                {
                    AnalyzeTestInfo_left(TestReslt.TestLeft, ResolveStr[j], configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[NowPoit_Location_Left], NowPoit_Location_Left);
                    this.Invoke((Action<RichTextBox>)(theRich => { theRich.AppendText(ResolveStr[j] + "\r"); }), richTextBox1);
                }
            }
           

        }

        private void RightTestBoard_ProcessMsg(string ip, string msg)
        {
            if (ip == configFile.TestBoard_Right_PortName)
            {
                string[] ResolveStr = Resolve(msg.Replace("\n", ""));
                for (int j = 0; j < ResolveStr.Length; j++)
                {
                    AnalyzeTestInfo_Right(TestReslt.TestRight, ResolveStr[j], configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[NowPoit_Location_Right], NowPoit_Location_Right);
                    this.Invoke((Action<RichTextBox>)(theRich => { theRich.AppendText(ResolveStr[j] + "\r"); }), richTextBox2);
                }

            }
        }
        private void InitCamera()
        {
            string ErrorMsg = "";
            if (Camera1.Open_Dev(configFile.Camera1Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机1打开异常\n";
            }
            else
            {
                Camera1.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera1ExposureTime);
            }
            if (Camera2.Open_Dev(configFile.Camera2Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机2打开异常\n";
            }
            else
            {
                Camera2.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera2ExposureTime);
            }
            if (Camera3.Open_Dev(configFile.Camera3Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机3打开异常\n";
            }
            else
            {
                Camera3.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera3ExposureTime);
            }
            if (Camera4.Open_Dev(configFile.Camera4Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机4打开异常\n";
            }
            else
            {
                Camera4.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera4ExposureTime);
            }

            if (Camera5.Open_Dev(configFile.Camera5Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机5打开异常\n";
            }
            else
            {
                Camera5.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera5ExposureTime);
            }
            if (Camera6.Open_Dev(configFile.Camera6Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机6打开异常\n";
            }
            else
            {
                Camera6.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera6ExposureTime);
            }
            if (Camera7.Open_Dev(configFile.Camera7Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机7打开异常\n";
            }
            else
            {
                Camera7.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera7ExposureTime);
            }
            if (Camera8.Open_Dev(configFile.Camera8Seria) != 0)
            {
                ErrorMsg = ErrorMsg + "相机8打开异常\n";
            }
            else
            {
                Camera8.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera8ExposureTime);
            }




            if (ErrorMsg != "")
            {
                MessageBox.Show(ErrorMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }


        //处理左边测试版的内容
        private void Process_SPinfo_Left()
        {
          
            while (SystemRunState == true)
            {
                if (SP_infoList_Left.Count > 0)
                {
                    for (int i = 0; i < SP_infoList_Left.Count; i++)
                    {
                        this.Invoke((Action<RichTextBox>)(theRich => { theRich.AppendText(SP_infoList_Left[i].Point.Name + ":" + SP_infoList_Left[i].IRString); theRich.HideSelection = false; }), richTextBox1);
                        AnalyzeTestInfo_left(TestReslt.TestLeft, SP_infoList_Left[i].IRString, SP_infoList_Left[i].Point, 0);
                        SP_infoList_Left.RemoveAt(i);

                    }
                    
                }
                Thread.Sleep(1);
            }
           
        }
        //处理右边测试板的内容
        private void Process_SPinfo_Right()
        {
            while (SystemRunState == true)
            {
                if (SP_infoList_Right.Count > 0)
                {
                    for (int i = 0; i < SP_infoList_Right.Count; i++)
                    {
                        this.Invoke((Action<RichTextBox>)(theRich => { theRich.AppendText(SP_infoList_Right[i].Point.Name + ":" + SP_infoList_Right[i].IRString); theRich.HideSelection = false; }), richTextBox2);
                        AnalyzeTestInfo_Right(TestReslt.TestRight, SP_infoList_Right[i].IRString, SP_infoList_Right[i].Point, i);
                        SP_infoList_Right.RemoveAt(i);
                    }
                }
                Thread.Sleep(1);
            }
        }

        private void Disp_KeyResult(HSmartWindowControl windowControl, HTuple homat, MotionPoint point, bool Result)
        {

        }

        private void Dsip_testResult(ListView listView, string content)
        {
            if (content.Contains("红外发光强度异常") == true)
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[0].BackColor = Color.Red; }), listView);
            }
            else
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[0].BackColor = Color.Green; }), listView);
            }

            if (content.Contains("动态电流") == true)
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[1].BackColor = Color.Red; }), listView);
            }
            else
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[1].BackColor = Color.Green; }), listView);
            }

            if (content.Contains("静态电流异常") == true)
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[2].BackColor = Color.Red; }), listView);
            }
            else
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[2].BackColor = Color.Green; }), listView);
            }

            if (content.Contains("载波异常") == true)
            {

                this.Invoke((Action<ListView>)(theListView => { theListView.Items[3].BackColor = Color.Red; }), listView);
            }
            else
            {

                this.Invoke((Action<ListView>)(theListView => { theListView.Items[3].BackColor = Color.Green; }), listView);
            }

            if (content.Contains("屏幕") == true)
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[4].BackColor = Color.Red; theListView.Items[4].SubItems[1].Text = "NG"; }), listView);
            }
            else
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[4].BackColor = Color.Green; theListView.Items[4].SubItems[1].Text = "OK"; }), listView);
            }

            if (content.Contains("按键") == true)
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[5].BackColor = Color.Red; theListView.Items[5].SubItems[1].Text = "NG"; }), listView);
            }
            else
            {
                this.Invoke((Action<ListView>)(theListView => { theListView.Items[5].BackColor = Color.Green; theListView.Items[5].SubItems[1].Text = "OK"; }), listView);
            }

        }
        private void AnalyzeTestInfo_left(TestStation station, string testinfo, MotionPoint point, int Falg)
        {
            string[] info = testinfo.Split(':');
            double Dynamiccurrent = 0;
            double Radiancy = 0;
            double CarrierFrequency = 0;
           

            switch (info.Length)
            {
                case 1:
                    break;
                case 2:
                    switch (info[0])
                    {
                        case "ch1":
                            station.Channel1.QuiescentCurrent = (Convert.ToDouble(info[1].TrimEnd('\r')) * 1000000) - 20;
                            listView3.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel1.QuiescentCurrent.ToString("0.000") + "uA"; }), listView3);
                            break;
                        case "ch2":
                            station.Channel2.QuiescentCurrent = (Convert.ToDouble(info[1].TrimEnd('\r')) * 1000000) - 20;
                            listView4.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel2.QuiescentCurrent.ToString("0.000") + "uA"; }), listView4);
                            break;
                        case "ch3":
                            station.Channel3.QuiescentCurrent = (Convert.ToDouble(info[1].TrimEnd('\r')) * 1000000) - 20;
                            listView5.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel3.QuiescentCurrent.ToString("0.000") + "uA"; }), listView5);
                            break;
                        case "ch4":
                            station.Channel4.QuiescentCurrent = (Convert.ToDouble(info[1].TrimEnd('\r')) * 1000000) - 20;

                            listView6.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel4.QuiescentCurrent.ToString("0.0000") + "uA"; }), listView6);
                            break;
                    }
                    break;
                case 5:
                    switch (info[0])
                    {
                        case "CH1":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel1.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel1.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel1.Radiancy.Add(Radiancy);

                            listView3.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView3);
                            listView3.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView3);
                            listView3.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView3);

                            ++LeftCodeNumber;
                            string[] Code_List1 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex1 = new List<string>();
                            IR_Code_Hex1.Clear();
                            string IR_code1 = "";
                            foreach (string code_str1 in Code_List1)
                            {
                                string tempstr = Tool.BinConvertHex(code_str1);
                                IR_Code_Hex1.Add(tempstr);
                                IR_code1 = IR_code1 + tempstr + ":";
                            }
                            Code_Station_Left = IR_code1;
                            station.Channel1.IR_Code_Now = IR_code1;
                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel1.IR_Code.Add(IR_code1);
                                if (Tool.compareCode(IR_Code_Hex1, point.IR_Code_List) == false)
                                {
                                    station.Channel1.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl10, KeyHomat_Left, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl10, KeyHomat_Left, point, true);
                                }
                            }
                            if (IRCode_InputMode_Left == true)
                            {
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[Falg].Code_Value = IR_code1;
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[Falg].Code_Value = IR_code1;
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[Falg].IR_Code_List = IR_Code_Hex1;
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[Falg].IR_Code_List = IR_Code_Hex1;
                               
                                this.BeginInvoke((Action<ListBox>)(theBox => {theBox.Items.Add(LeftCodeNumber.ToString() + " " + point.Name + ":" + IR_code1); }), IR_BOX1);
                            }
                            else
                            {

                                if (Station_RunLeft == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(LeftCodeNumber.ToString() + " " + IR_code1); }), IR_BOX1);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => {theBox.Items.Add(LeftCodeNumber.ToString() + " " + point.Name + ":" + IR_code1 + ";对照码值:" + point.Code_Value);  }), IR_BOX1); station.Channel1.IR_Feature_Count++; }
                                }
                            }
                            break;
                        case "CH2":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel2.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel2.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel2.Radiancy.Add(Radiancy);

                            listView4.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView4);
                            listView4.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView4);
                            listView4.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView4);

                            ++LeftCodeNumber1;
                            string[] Code_List2 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex2 = new List<string>();
                            IR_Code_Hex2.Clear();
                            string IR_code2 = "";
                            foreach (string code_str2 in Code_List2)
                            {
                                string tempstr = Tool.BinConvertHex(code_str2);
                                IR_Code_Hex2.Add(tempstr);
                                IR_code2 = IR_code2 + tempstr + ":";
                            }
                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel2.IR_Code.Add(IR_code2);
                                if (Tool.compareCode(IR_Code_Hex2, point.IR_Code_List) == false)
                                {
                                    station.Channel2.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl11, KeyHomat_Left, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl11, KeyHomat_Left, point, true);
                                }
                            }
                            Code_Station_Left = IR_code2;
                            station.Channel2.IR_Code_Now = IR_code2;
                            if (IRCode_InputMode_Left == false)
                            {
                                if (Station_RunLeft == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(IR_code2); }), IR_BOX2);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => {theBox.Items.Add(LeftCodeNumber1.ToString() + " " + point.Name + ":" + IR_code2 + ";对照码值:" + point.Code_Value); }), IR_BOX2); station.Channel2.IR_Feature_Count++; }
                                }
                            }
                            break;
                        case "CH3":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel3.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel3.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel3.Radiancy.Add(Radiancy);

                            listView5.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView5);
                            listView5.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView5);
                            listView5.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView5);

                            ++LeftCodeNumber2;
                            string[] Code_List3 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex3 = new List<string>();
                            IR_Code_Hex3.Clear();
                            string IR_code3 = "";
                            foreach (string code_str3 in Code_List3)
                            {
                                string tempstr = Tool.BinConvertHex(code_str3);
                                IR_Code_Hex3.Add(tempstr);
                                IR_code3 = IR_code3 + tempstr + ":";
                            }
                            Code_Station_Left = IR_code3;
                            station.Channel3.IR_Code_Now = IR_code3;
                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel3.IR_Code.Add(IR_code3);
                                if (Tool.compareCode(IR_Code_Hex3, point.IR_Code_List) == false)
                                {
                                    station.Channel3.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl12, KeyHomat_Left, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl12, KeyHomat_Left, point, true);
                                }
                            }
                            if (IRCode_InputMode_Left == false)
                            {
                                if (Station_RunLeft == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(IR_code3); }), IR_BOX3);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(LeftCodeNumber2.ToString() + " " + point.Name + ":" + IR_code3 + ";对照码值:" + point.Code_Value); }), IR_BOX3); station.Channel3.IR_Feature_Count++; }
                                }
                            }
                            break;
                        case "CH4":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel4.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel4.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel4.Radiancy.Add(Radiancy);

                            ++LeftCodeNumber3;
                            string[] Code_List4 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex4 = new List<string>();
                            IR_Code_Hex4.Clear();
                            string IR_code4 = "";
                            foreach (string code_str4 in Code_List4)
                            {
                                string tempstr = Tool.BinConvertHex(code_str4);
                                IR_Code_Hex4.Add(tempstr);
                                IR_code4 = IR_code4 + tempstr + ":";
                            }
                            Code_Station_Left = IR_code4;
                            station.Channel4.IR_Code_Now = IR_code4;

                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel4.IR_Code.Add(IR_code4);
                                if (Tool.compareCode(IR_Code_Hex4, point.IR_Code_List) == false)
                                {
                                    station.Channel4.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl13, KeyHomat_Left, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl13, KeyHomat_Left, point, true);
                                }
                            }
                            if (IRCode_InputMode_Left == false)
                            {
                                if (Station_RunLeft == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(IR_code4); }), IR_BOX4);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(LeftCodeNumber3.ToString() + " " + point.Name + ":" + IR_code4 + ";对照码值:" + point.Code_Value); }), IR_BOX4); station.Channel4.IR_Feature_Count++; }
                                }
                            }
                            listView6.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView6);
                            listView6.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView6);
                            listView6.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView6);
                            break;
                    }
                    break;


            }
        }
        private void AnalyzeTestInfo_Right(TestStation station, string testinfo, MotionPoint point, int Falg)
        {

            string[] info = testinfo.Split(':');
            double Dynamiccurrent = 0;
            double Radiancy = 0;
            double CarrierFrequency = 0;
            switch (info.Length)
            {
                case 1:
                    break;
                case 2:
                    switch (info[0])
                    {
                        case "ch1":
                            station.Channel1.QuiescentCurrent = (Convert.ToDouble(info[1].Trim('\r')) * 1000000) - 21;
                            listView7.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel1.QuiescentCurrent.ToString("0.000") + "uA"; }), listView7);
                            break;
                        case "ch2":
                            station.Channel2.QuiescentCurrent = (Convert.ToDouble(info[1].Trim('\r')) * 1000000) - 21;
                            listView8.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel2.QuiescentCurrent.ToString("0.000") + "uA"; }), listView8);
                            break;
                        case "ch3":
                            station.Channel3.QuiescentCurrent = (Convert.ToDouble(info[1].Trim('\r')) * 1000000) - 22;
                            listView9.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel3.QuiescentCurrent.ToString("0.000") + "uA"; }), listView9);
                            break;
                        case "ch4":
                            station.Channel4.QuiescentCurrent = (Convert.ToDouble(info[1].Trim('\r')) * 1000000) - 20;
                            listView10.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = station.Channel4.QuiescentCurrent.ToString("0.000") + "uA"; }), listView10);
                            break;
                    }
                    break;
                case 5:
                    switch (info[0])
                    {
                        case "CH1":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel1.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel1.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel1.Radiancy.Add(Radiancy);

                            listView7.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView7);
                            listView7.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView7);
                            listView7.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView7);

                            ++RightCodeNumber;
                            string[] Code_List1 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex1 = new List<string>();
                            IR_Code_Hex1.Clear();
                            string IR_code1 = "";
                            foreach (string code_str1 in Code_List1)
                            {
                                string tempstr = Tool.BinConvertHex(code_str1);
                                IR_Code_Hex1.Add(tempstr);
                                IR_code1 = IR_code1 + tempstr + ":";
                            }

                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel1.IR_Code.Add(IR_code1);
                                if (Tool.compareCode(IR_Code_Hex1, point.IR_Code_List) == false)
                                {
                                    station.Channel1.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl14, KeyHomat_Right, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl14, KeyHomat_Right, point, true);
                                }
                            }
                            Code_Station_Right = IR_code1;
                            station.Channel1.IR_Code_Now = IR_code1;



                            if (IRCode_InputMode_Right == true)
                            {
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[Falg].Code_Value = IR_code1;
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[Falg].Code_Value = IR_code1;
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[Falg].IR_Code_List = IR_Code_Hex1;
                                configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[Falg].IR_Code_List = IR_Code_Hex1;
                                this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(RightCodeNumber.ToString() + " " + point.Name + ":" + IR_code1); }), IR_BOX5);
                            }
                            else
                            {
                                if (Station_RunRight == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(RightCodeNumber.ToString() + " " + IR_code1); }), IR_BOX5);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(RightCodeNumber.ToString() + " " + point.Name + ":" + IR_code1 + ";对照码值:" + point.Code_Value); }), IR_BOX5); station.Channel1.IR_Feature_Count++; }

                                }
                            }
                            break;
                        case "CH2":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel2.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel2.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel2.Radiancy.Add(Radiancy);

                            listView8.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView8);
                            listView8.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView8);
                            listView8.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView8);

                            ++RightCodeNumber1;
                            string[] Code_List2 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex2 = new List<string>();
                            IR_Code_Hex2.Clear();
                            string IR_code2 = "";
                            foreach (string code_str2 in Code_List2)
                            {
                                string tempstr = Tool.BinConvertHex(code_str2);
                                IR_Code_Hex2.Add(tempstr);
                                IR_code2 = IR_code2 + tempstr + ":";
                            }
                            Code_Station_Right = IR_code2;
                            station.Channel2.IR_Code_Now = IR_code2;

                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel2.IR_Code.Add(IR_code2);
                                if (Tool.compareCode(IR_Code_Hex2, point.IR_Code_List) == false)
                                {
                                    station.Channel2.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl15, KeyHomat_Right, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl15, KeyHomat_Right, point, true);
                                }
                            }
                            if (IRCode_InputMode_Right == false)
                            {
                                if (Station_RunRight == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(IR_code2); }), IR_BOX6);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(RightCodeNumber1.ToString() + " " + point.Name + ":" + IR_code2 + ";对照码值:" + point.Code_Value); }), IR_BOX6); station.Channel2.IR_Feature_Count++; }

                                }
                            }
                            break;
                        case "CH3":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel3.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel3.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel3.Radiancy.Add(Radiancy);

                            listView9.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView9);
                            listView9.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView9);
                            listView9.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView9);

                            ++RightCodeNumber2;
                            string[] Code_List3 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex3 = new List<string>();
                            IR_Code_Hex3.Clear();
                            string IR_code3 = "";
                            foreach (string code_str3 in Code_List3)
                            {
                                string tempstr = Tool.BinConvertHex(code_str3);
                                IR_Code_Hex3.Add(tempstr);
                                IR_code3 = IR_code3 + tempstr + ":";
                            }
                            Code_Station_Right = IR_code3;
                            station.Channel2.IR_Code_Now = IR_code3;


                            Code_Station_Right = IR_code3;
                            station.Channel3.IR_Code_Now = IR_code3;

                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel3.IR_Code.Add(IR_code3);
                                if (Tool.compareCode(IR_Code_Hex3, point.IR_Code_List) == false)
                                {
                                    station.Channel3.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl16, KeyHomat_Right, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl16, KeyHomat_Right, point, true);
                                }
                            }
                            if (IRCode_InputMode_Right == false)
                            {
                                if (Station_RunRight == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(IR_code3); }), IR_BOX7);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(RightCodeNumber2.ToString() + " " + point.Name + ":" + IR_code3 + ";对照码值:" + point.Code_Value); }), IR_BOX7); station.Channel3.IR_Feature_Count++; }
                                }
                            }
                            break;
                        case "CH4":
                            Dynamiccurrent = Convert.ToDouble(info[2]) * 1000;
                            Radiancy = Convert.ToDouble(info[3]);
                            CarrierFrequency = Math.Round(GetCarrierFrequency(info[1], info[4]) / 1000, 3);
                            station.Channel4.CarrierFrequency.Add(CarrierFrequency);
                            station.Channel4.Dynamiccurrent.Add(Dynamiccurrent);
                            station.Channel4.Radiancy.Add(Radiancy);

                            listView10.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = Radiancy + "mA"; }), listView10);
                            listView10.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = Dynamiccurrent + "mA"; }), listView10);
                            listView10.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = CarrierFrequency + "KHz"; }), listView10);

                            ++RightCodeNumber3;
                            string[] Code_List4 = info[1].Replace("L", "").Split('S');
                            List<string> IR_Code_Hex4 = new List<string>();
                            IR_Code_Hex4.Clear();
                            string IR_code4 = "";
                            foreach (string code_str4 in Code_List4)
                            {
                                string tempstr = Tool.BinConvertHex(code_str4);
                                IR_Code_Hex4.Add(tempstr);
                                IR_code4 = IR_code4 + tempstr + ":";
                            }
                            Code_Station_Right = IR_code4;
                            station.Channel2.IR_Code_Now = IR_code4;

                            Code_Station_Right = IR_code4;
                            station.Channel4.IR_Code_Now = IR_code4;
                            if (point.pointStyle == PointStyle.KeyTest && point.Code_Value != "")
                            {
                                station.Channel4.IR_Code.Add(IR_code4);
                                if (Tool.compareCode(IR_Code_Hex4, point.IR_Code_List) == false)
                                {
                                    station.Channel4.IR_TestItem.Add(point.Name);
                                    Disp_KeyResult(hSmartWindowControl17, KeyHomat_Right, point, false);
                                }
                                else
                                {
                                    Disp_KeyResult(hSmartWindowControl17, KeyHomat_Right, point, true);
                                }
                            }
                            if (IRCode_InputMode_Right == false)
                            {
                                if (Station_RunRight == false)
                                {
                                    this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(IR_code4); }), IR_BOX8);
                                }
                                else
                                {
                                    if (point.Code_Value != "") { this.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Add(RightCodeNumber3.ToString() + " " + point.Name + ":" + IR_code4 + ";对照码值:" + point.Code_Value); }), IR_BOX8); station.Channel4.IR_Feature_Count++; }

                                }
                            }
                            break;
                    }
                    break;


            }

        }
        private double GetCarrierFrequency(string Code, string CycleList)
        {
            try
            {
                List<double> CarrierFrequency = new List<double>();
                string Code1 = Code.Replace("L", "");
                char[] Code2 = Code1.ToCharArray();
                if (Code2.Length > 0)
                {
                    List<string> CycleList1 = CycleList.Split(',').ToList<string>();
                    CycleList1.RemoveAt(0);
                    CycleList1.RemoveAt(CycleList1.Count - 1);
                    CarrierFrequency.Clear();
                    if (CycleList1.Count > 0 && Code2.Length > 0)
                    {
                        for (int i = 0; i < CycleList1.Count; i++)
                        {
                            if (Code2[i] == '1')
                            {
                                try
                                {
                                    double aa = Convert.ToDouble(CycleList1[i]) / (Math.Round(Convert.ToDouble(CycleList1[i]) / 26.4, 0));
                                    double bb = aa / 1000000;
                                    double cc = 1 / bb;
                                    CarrierFrequency.Add(cc);
                                }
                                catch
                                {

                                }
                            }
                        }
                        return CarrierFrequency.Average();
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                {
                    return 0;
                }
            }
            catch
            {
                return 0;
            }
        }
        private void Form1_Shown(object sender, EventArgs e)
        {
            HikVisionCamera.InitCameraList();
            InitUi();
            InitCamera();
            InitSerialPort();
            ConnectMotionControl();
            ApplyAxisParameter(axisParameter);
            //读取IO输入输出状态
            IOStatus_Task = new Task(IOStatus);
            IOStatus_Task.Start();
            // 读取轴参数大的现场
            AxisState_task = new Task(readAxisState);
            AxisState_task.Start();
            InitExamineFeature();
            //左侧工位的工作线程
            Station_Left_Task = new Thread(Station_Left);
            Station_Left_Task.IsBackground = true;
            Station_Left_Task.Start();

            Station_Right_Task = new Thread(Station_Right);
            Station_Right_Task.IsBackground = true;
            Station_Right_Task.Start();

            InitPLC();
            Task Auto_DeletDir_Screen = Task.Run(() => AutoDeleteDir(@"F:\SaveImage\ScreenTest\", configFile.SavaImageTime));
            Task Auto_DeletDir_Key = Task.Run(() => AutoDeleteDir(@"F:\SaveImage\KeyTest\", configFile.SavaImageTime));
            Task Test_Task = Task.Run((Action)Test_Queue_Run);

            if (comboBox11.Items.Count > 0) comboBox11.SelectedIndex = 0;
            if (comboBox6.Items.Count > 0) comboBox6.SelectedIndex = 0;
            if (comboBox7.Items.Count > 0) comboBox7.SelectedIndex = 0;

            this.WindowState = FormWindowState.Maximized;
        }

        private void Test_Queue_Run()
        {
            while (SystemRunState)
            {
                if (TestList.Count > 0)
                {
                    for (int i = 0; i < TestList.Count; i++)
                    {
                        TestList[i].Run();
                        TestList.RemoveAt(i);
                    }
                }

                Thread.Sleep(200);
            }
        }


        private void SaveDataToTxtBox(TextBox textBox, ref float Value)
        {
            if (textBox.Text != null)
            {
                try
                {
                    Value = Convert.ToSingle(textBox.Text);
                }
                catch
                {
                    MessageBox.Show("请输入一个合理的数值");
                    textBox.Text = "0";
                    Value = 0;
                }
            }
        }
        private void SaveDataToTxtBox(TextBox textBox, ref double Value)
        {
            if (textBox.Text != null)
            {
                try
                {
                    Value = Convert.ToDouble(textBox.Text);
                }
                catch
                {
                    MessageBox.Show("请输入一个合理的数值");
                    textBox.Text = "0";
                    Value = 0;
                }
            }
        }
        private void SaveDataToTxtBox(TextBox textBox, ref string Value)
        {
            if (textBox.Text != null)
            {
                try
                {
                    Value = textBox.Text;
                }
                catch
                {
                    MessageBox.Show("请输入一个合理的数值");
                    textBox.Text = "0";
                }
            }
        }

        private void AutoDeleteDir(string DirPath, double TimeLong)
        {
            while (true)
            {

                try
                {
                    //判断目录是否存在
                    if (Directory.Exists(DirPath) == true)
                    {
                        string[] dirList = Directory.GetDirectories(DirPath);
                        if (dirList.Length > 0)
                        {
                            for (int i = 0; i < dirList.Length; i++)
                            {
                                if (DateTime.Now.Subtract(Directory.GetCreationTime(dirList[i])).TotalHours > TimeLong)
                                {
                                    Directory.Delete(dirList[i], true);
                                }
                            }
                        }
                    }
                }
                catch
                {

                }

                Thread.Sleep(1000 * 60 * 5);
            }

        }
        private void SaveDataToTxtBox(TextBox textBox, ref int Value)
        {
            if (textBox.Text != null)
            {
                try
                {
                    Value = Convert.ToInt16(textBox.Text);
                }
                catch
                {
                    MessageBox.Show("请输入一个合理的数值");
                    textBox.Text = "0";
                    Value = 0;
                }
            }
        }
        /// <summary>
        /// 初始化UI
        /// </summary>
        private void InitUi()
        {
            //初始化轴参数
            try
            {
                FileStream fileStream = new FileStream(Directory.GetCurrentDirectory() + @"\Config\axisParameter.json", FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fileStream, Encoding.Default);
                String JsonTxt = streamReader.ReadToEnd();
                streamReader.Close();
                fileStream.Close();
                axisParameter = JsonConvert.DeserializeObject<AxisParameter>(JsonTxt);

                textBox1.Text = axisParameter.Axis1Speed.ToString();
                textBox2.Text = axisParameter.Axis1Units.ToString();
                textBox3.Text = axisParameter.Axis1Accel.ToString();
                textBox4.Text = axisParameter.Axis1Decel.ToString();

                textBox8.Text = axisParameter.Axis2Speed.ToString();
                textBox6.Text = axisParameter.Axis2Units.ToString();
                textBox7.Text = axisParameter.Axis2Accel.ToString();
                textBox5.Text = axisParameter.Axis2Decel.ToString();

                textBox12.Text = axisParameter.Axis5Speed.ToString();
                textBox10.Text = axisParameter.Axis5Units.ToString();
                textBox11.Text = axisParameter.Axis5Accel.ToString();
                textBox9.Text = axisParameter.Axis5Decel.ToString();


                textBox24.Text = axisParameter.Axis3Speed.ToString();
                textBox22.Text = axisParameter.Axis3Units.ToString();
                textBox23.Text = axisParameter.Axis3Accel.ToString();
                textBox21.Text = axisParameter.Axis3Decel.ToString();

                textBox20.Text = axisParameter.Axis4Speed.ToString();
                textBox18.Text = axisParameter.Axis4Units.ToString();
                textBox19.Text = axisParameter.Axis4Accel.ToString();
                textBox17.Text = axisParameter.Axis4Decel.ToString();

                textBox16.Text = axisParameter.Axis6Speed.ToString();
                textBox14.Text = axisParameter.Axis6Units.ToString();
                textBox15.Text = axisParameter.Axis6Accel.ToString();
                textBox13.Text = axisParameter.Axis6Decel.ToString();

                textBox53.Text = axisParameter.Station_Left_SafetyHight.ToString();
                textBox56.Text = axisParameter.Station_Left_Zoffset.ToString();
                textBox55.Text = axisParameter.Station_Right_SafetyHight.ToString();
                textBox54.Text = axisParameter.Station_Right_Zoffset.ToString();



                //配置信息初始化
                FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\Config.json", FileMode.Open, FileAccess.Read);
                StreamReader streamReader1 = new StreamReader(fileStream1, Encoding.Default);
                String Json_Config = streamReader1.ReadToEnd();
                streamReader1.Close();
                fileStream1.Close();
                configFile = JsonConvert.DeserializeObject<Config>(Json_Config);
                NowProductID = FindProductID(configFile.CurrentMode, configFile);
                textBox77.Text = configFile.productList[NowProductID].GetScreen_Scaled_Value1.ToString();
                textBox93.Text = configFile.productList[NowProductID].GetScreen_Scaled_Value2.ToString();
                textBox100.Text = configFile.productList[NowProductID].Screen_AreaMin.ToString();
                textBox75.Text = configFile.SavaImageTime.ToString();
                algorithm.Scaled_Value1 = configFile.productList[NowProductID].GetScreen_Scaled_Value1;
                algorithm.Scaled_Value2 = configFile.productList[NowProductID].GetScreen_Scaled_Value2;
                algorithm.Screen_AreaMin = configFile.productList[NowProductID].Screen_AreaMin;
                textBox104.Text = configFile.productList[NowProductID].Key_AreaMin.ToString();

                label173.Text = Convert.ToString(configFile.LeftHomeX);
                label175.Text = Convert.ToString(configFile.LeftHomeY);
                label177.Text = Convert.ToString(configFile.LeftHomeZ);

                label182.Text = Convert.ToString(configFile.RightHomeX);
                label180.Text = Convert.ToString(configFile.RightHomeY);
                label178.Text = Convert.ToString(configFile.RightHomeZ);


                foreach (KeyValuePair<string, MotionControl_Info> i in configFile.MotionControl_List)
                {
                    comboBox11.Items.Add(i.Key);
                }
                try
                {
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints.Count > 0)
                    {
                        comboBox11.Text = configFile.productList[NowProductID].MotionControl_Name;
                    }
                }
                catch (Exception)
                {
                    comboBox11.Text = null;

                }

                if (configFile.Screen_Model_List.Count>0)
                {
                    for(int i =0;i<configFile.Screen_Model_List.Count;i++)
                    {
                        comboBox7.Items.Add(configFile.Screen_Model_List[i]);
                    }
                    //comboBox7.SelectedIndex = 0;
                    comboBox7.Text = configFile.productList[NowProductID].Screen_Model;
                }

                if (configFile.Key_Model_List.Count > 0)
                {
                    for (int i = 0; i < configFile.Key_Model_List.Count; i++)
                    {
                        comboBox6.Items.Add(configFile.Key_Model_List[i]);
                    }
                    //comboBox6.SelectedIndex = 0;
                    comboBox6.Text = configFile.productList[NowProductID].Key_Model;
                }

                if (configFile.PLC_Start == true)
                {
                    checkBox6.Checked = true;
                }
                else
                {
                    checkBox6.Checked = false;
                }

                textBox76.Text = configFile.PLC_address.StartLeft;
                textBox80.Text = configFile.PLC_address.GetMateriel_Left;
                textBox82.Text = configFile.PLC_address.TestComplete_Left;
                textBox84.Text = configFile.PLC_address.TestReult1_Left;
                textBox86.Text = configFile.PLC_address.TestReult2_Left;
                textBox88.Text = configFile.PLC_address.TestReult3_Left;
                textBox90.Text = configFile.PLC_address.TestReult4_Left;

                textBox79.Text = configFile.PLC_address.StartRight;
                textBox81.Text = configFile.PLC_address.GetMateriel_Right;
                textBox83.Text = configFile.PLC_address.TestComplete_Right;
                textBox85.Text = configFile.PLC_address.TestReult1_Right;
                textBox87.Text = configFile.PLC_address.TestReult2_Right;
                textBox89.Text = configFile.PLC_address.TestReult3_Right;
                textBox91.Text = configFile.PLC_address.TestReult4_Right;

                textBox105.Text = configFile.PLC_address.Left_StationIsEmpty;
                textBox106.Text = configFile.PLC_address.Right_StationIsEmpty;
                textBox92.Text = configFile.PLCIP;

                if (configFile.Shield_ScreenTest == true) checkBox2.Checked = true;
                if (configFile.Shield_KeyTest == true) checkBox3.Checked = true;

                if (configFile.Total_Item.Count == 0)
                {
                    //初始化统计项目
                    configFile.Total_Item.Add("屏幕", 0);
                    configFile.Total_Item.Add("按键", 0);
                    configFile.Total_Item.Add("红外测试", 0);
                    configFile.Total_Item.Add("发光强度", 0);
                    configFile.Total_Item.Add("静态电流", 0);
                    configFile.Total_Item.Add("动态电流", 0);
                    configFile.Total_Item.Add("载波频率", 0);
                    configFile.Total_Item.Add("红外信号", 0);
                    configFile.Total_Item.Add("空载", 0);
                }

                if (configFile.ToDay != "")
                {
                    label185.Text = configFile.ToDay;
                }
                else
                {
                    configFile.ToDay = DateTime.Today.ToString("yyyy-MM-dd");
                    label185.Text = configFile.ToDay;
                }

                //点位信息初始化

                Refresh_Motion_Left();
                Refresh_Motion_Right();



            }
            catch
            {
                MessageBox.Show("读取置文件异常");
            }

            //初始化ListView
            InitListView_PointList(listView1);
            InitListView_PointList(listView2);
            InitListView_HomePage(listView3);
            InitListView_HomePage(listView4);
            InitListView_HomePage(listView5);
            InitListView_HomePage(listView6);
            InitListView_HomePage(listView7);
            InitListView_HomePage(listView8);
            InitListView_HomePage(listView9);
            InitListView_HomePage(listView10);



            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.Items.Add(configFile.Camera1Seria + ":(左1)");
            comboBox3.Items.Add(configFile.Camera2Seria + ":(左2)");
            comboBox3.Items.Add(configFile.Camera3Seria + ":(左3)");
            comboBox3.Items.Add(configFile.Camera4Seria + ":(左4)");
            comboBox3.Items.Add(configFile.Camera5Seria + ":(右1)");
            comboBox3.Items.Add(configFile.Camera6Seria + ":(右2)");
            comboBox3.Items.Add(configFile.Camera7Seria + ":(右3)");
            comboBox3.Items.Add(configFile.Camera8Seria + ":(右4)");

            if (configFile.productList.Count > 0)
            {
                textBox40.Text = configFile.productList[NowProductID].Config.QuiescentCurrentMax.ToString();
                textBox42.Text = configFile.productList[NowProductID].Config.QuiescentCurrentMin.ToString();

                textBox41.Text = configFile.productList[NowProductID].Config.DynamiccurrentMax.ToString();
                textBox43.Text = configFile.productList[NowProductID].Config.DynamiccurrentMin.ToString();

                textBox44.Text = configFile.productList[NowProductID].Config.CarrierFrequencyMax.ToString();

                textBox45.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel1.ToString();
                textBox46.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel2.ToString();
                textBox47.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel3.ToString();
                textBox48.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel4.ToString();
                textBox49.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel1.ToString();
                textBox50.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel2.ToString();
                textBox51.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel3.ToString();
                textBox52.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel4.ToString();
                textBox57.Text = configFile.productList[NowProductID].Config.CarrierFrequencyMin.ToString();
                textBox72.Text = configFile.productList[NowProductID].IR_Count.ToString();

            }

            textBox64.Text = configFile.Camera1Seria;
            textBox65.Text = configFile.Camera2Seria;
            textBox66.Text = configFile.Camera3Seria;
            textBox67.Text = configFile.Camera4Seria;
            textBox68.Text = configFile.Camera5Seria;
            textBox69.Text = configFile.Camera6Seria;
            textBox70.Text = configFile.Camera7Seria;
            textBox71.Text = configFile.Camera8Seria;


            textBox73.Text = configFile.TestBoard_Left_PortName;
            textBox74.Text = configFile.TestBoard_Right_PortName;

            if (configFile.Regionfoshan == true)
            {
                checkBox7.Checked = true;
            }
            else
            {
                checkBox7.Checked = false;
            }


            listBox2.Items.Clear();
            try
            {
                string[] ScreenFearure = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\ModelID");
                if (ScreenFearure.Length > 0)
                {
                    for (int i = 0; i < ScreenFearure.Length; i++)
                    {
                        listBox2.Items.Add("特征:" + (i + 1));
                    }
                }
            }
            catch
            {
                MessageBox.Show("遍历屏幕模板文件异常");
            }

            listBox3.Items.Clear();
            try
            {
                string[] ScreenFearure = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Key_Model + @"\ModelID_Key");
                if (ScreenFearure.Length > 0)
                {
                    for (int i = 0; i < ScreenFearure.Length; i++)
                    {
                        listBox3.Items.Add("特征:" + (i + 1));
                    }
                }
            }
            catch
            {
                MessageBox.Show("遍历按键模板文件异常");
            }



            if (configFile.productList.Count > 0)
            {
                for (int i = 0; i < configFile.productList.Count; i++)
                {
                    listBox1.Items.Add(configFile.productList[i].Model);
                }
            }



            if (configFile.productList[NowProductID].P_Style == Product.Product_Style.RomoteControl_White)
            {
                label61.Text = configFile.productList[NowProductID].Model + "（白色）";
                radioButton1.Checked = true;
                radioButton3.Checked = true;
            }

            if (configFile.productList[NowProductID].P_Style == Product.Product_Style.RomoteControl_black)
            {
                label61.Text = configFile.productList[NowProductID].Model + "（黑色）";
                radioButton2.Checked = true;
                radioButton4.Checked = true;
            }

            comboBox5.SelectedIndex = 0;
            comboBox4.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;
            radioButton6.Checked = true;



            TestWindow_Left.Add(hSmartWindowControl1);
            TestWindow_Left.Add(hSmartWindowControl2);
            TestWindow_Left.Add(hSmartWindowControl3);
            TestWindow_Left.Add(hSmartWindowControl4);

            TestWindow_Left.Add(hSmartWindowControl10);
            TestWindow_Left.Add(hSmartWindowControl11);
            TestWindow_Left.Add(hSmartWindowControl12);
            TestWindow_Left.Add(hSmartWindowControl13);


            TestWindow_Right.Add(hSmartWindowControl5);
            TestWindow_Right.Add(hSmartWindowControl6);
            TestWindow_Right.Add(hSmartWindowControl7);
            TestWindow_Right.Add(hSmartWindowControl8);

            TestWindow_Right.Add(hSmartWindowControl14);
            TestWindow_Right.Add(hSmartWindowControl15);
            TestWindow_Right.Add(hSmartWindowControl16);
            TestWindow_Right.Add(hSmartWindowControl17);


            //初始化统计列表
            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Total") == true)
            {
                string[] TotalList = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\Total");
                if (TotalList.Length > 0)
                {
                    for (int i = 0; i < TotalList.Length; i++)
                    {
                        Day_Total_Item item = new Day_Total_Item();
                        FileStream fileStream1 = new FileStream(TotalList[i], FileMode.Open, FileAccess.Read);
                        StreamReader streamReader1 = new StreamReader(fileStream1, Encoding.Default);
                        String Json_Config = streamReader1.ReadToEnd();
                        streamReader1.Close();
                        fileStream1.Close();
                        item = JsonConvert.DeserializeObject<Day_Total_Item>(Json_Config);
                        listBox8.Items.Add(item);
                    }
                }
            }

        }
        /// <summary>
        /// IO状态获取
        /// </summary>
        private void IOStatus()
        {
            uint Value = 0;
            while (SystemRunState)
            {
                if (autoRunMode == false)
                {
                    autoState = false;
                    //输出控制
                    for (int i = 3; i < OutputList_Control_IOCard.Length; i++)
                    {
                        this.Invoke((Action<CheckBox>)(theBox => { theBox.Enabled = true; }), OutputList_Control_IOCard[i]);
                        try
                        {
                            if (OutputList_Control_IOCard[i].Checked == true)
                            {
                                zmcaux.ZAux_Direct_SetOp(Phandle, i + 64, 1);
                            }
                            else
                            {
                                zmcaux.ZAux_Direct_SetOp(Phandle, i + 64, 0);
                            }

                        }
                        catch
                        {

                        }
                    }

                    for (int i = 0; i < OutputList_Control_PCICard.Length; i++)
                    {

                        this.Invoke((Action<CheckBox>)(theBox => { theBox.Enabled = true; }), OutputList_Control_PCICard[i]);
                        try
                        {
                            if (OutputList_Control_PCICard[i].Checked == true)
                            {
                                zmcaux.ZAux_Direct_SetOp(Phandle, i, 1);
                            }
                            else
                            {
                                zmcaux.ZAux_Direct_SetOp(Phandle, i, 0);
                            }

                        }
                        catch
                        {

                        }
                    }

                    for (int i = 0; i < InputList_Control.Length; i++)
                    {
                        zmcaux.ZAux_Direct_GetIn(Phandle, i + 64, ref Value);
                        if (Value == 1) this.Invoke((Action<CheckBox>)(theBox => { theBox.Checked = true; }), InputList_Control[i]);
                    }
                }
                else
                {
                    autoState = true;
                    for (int i = 0; i < OutputList_Control_IOCard.Length; i++)
                    {
                        this.Invoke((Action<CheckBox>)(theBox => { theBox.Enabled = false; theBox.Checked = false; }), OutputList_Control_IOCard[i]);
                    }
                }
                if (SystemRunState == false) break;


                //超过三天的图片删除
                string[] Screen_dirList = new string[] { };
                string[] Key_dirList = new string[] { };
                if (Directory.Exists(@"F:\SaveImage\ScreenTest") == true)
                {
                    Screen_dirList = Directory.GetDirectories(@"F:\SaveImage\ScreenTest");
                }
                if (Directory.Exists(@"F:\SaveImage\KeyTest") == true)
                {
                    Key_dirList = Directory.GetDirectories(@"F:\SaveImage\KeyTest");
                }
                foreach (string dir in Screen_dirList)
                {
                    if (DateTime.Now.Subtract(Directory.GetCreationTime(dir)).TotalDays > 3)
                    {
                        Directory.Delete(dir, true);
                    }
                }

                foreach (string dir in Key_dirList)
                {
                    if (DateTime.Now.Subtract(Directory.GetCreationTime(dir)).TotalDays > 3)
                    {
                        Directory.Delete(dir, true);
                    }
                }


                Thread.Sleep(100);
            }

        }
        private void readAxisState()
        {
            uint Safety_Door = 0;
            uint Reset_Left = 0;
            uint Reset_Right = 0;
            uint Left_Power_tighten = 0;
            uint Right_Power_tighten = 0;

            bool Scram_State = false;


            bool Start_Left = false;
            bool Start_Rigth = false;
            bool Stop_Status_Left = false;
            bool Stop_Status_Right = false;

            while (SystemRunState)
            {

                zmcaux.ZAux_Direct_GetIn(Phandle, 64 + 6, ref Scram);
                zmcaux.ZAux_Direct_GetIn(Phandle, 64 + 7, ref Safety_Door);
                zmcaux.ZAux_Direct_GetIn(Phandle, 64 + 2, ref Reset_Left);
                zmcaux.ZAux_Direct_GetIn(Phandle, 64 + 5, ref Reset_Right);
                zmcaux.ZAux_Direct_GetOp(Phandle, 64 + 9, ref Left_Power_tighten);
                zmcaux.ZAux_Direct_GetOp(Phandle, 64 + 13, ref Right_Power_tighten);

                zmcaux.ZAux_Direct_GetMpos(Phandle, 0, ref axisParameter.Axis1Mpos);
                this.Invoke((Action<Label>)(theLable => { theLable.Text = (axisParameter.Axis1Mpos).ToString("0.000"); }), label16);
                zmcaux.ZAux_Direct_GetMpos(Phandle, 1, ref axisParameter.Axis2Mpos);
                this.Invoke((Action<Label>)(theLable => { theLable.Text = (axisParameter.Axis2Mpos).ToString("0.000"); }), label18);
                zmcaux.ZAux_Direct_GetMpos(Phandle, 2, ref axisParameter.Axis3Mpos);
                this.Invoke((Action<Label>)(theLable => { theLable.Text = (axisParameter.Axis3Mpos).ToString("0.000"); }), label19);
                zmcaux.ZAux_Direct_GetMpos(Phandle, 3, ref axisParameter.Axis4Mpos);
                this.Invoke((Action<Label>)(theLable => { theLable.Text = (axisParameter.Axis4Mpos).ToString("0.000"); }), label21);
                zmcaux.ZAux_Direct_GetMpos(Phandle, 4, ref axisParameter.Axis5Mpos);
                this.Invoke((Action<Label>)(theLable => { theLable.Text = (axisParameter.Axis5Mpos).ToString("0.000"); }), label14);
                zmcaux.ZAux_Direct_GetMpos(Phandle, 5, ref axisParameter.Axis6Mpos);
                this.Invoke((Action<Label>)(theLable => { theLable.Text = (axisParameter.Axis6Mpos).ToString("0.000"); }), label22);
                //急停触发，运动停止
                //if ((Scram == 0 || Safety_Door == 0) && Scram_State == false && Safety_Door_State == false)
                if (Scram == 0 && Scram_State == false)
                {
                    Scram_State = true;
                    zmcaux.ZAux_Direct_Rapidstop(Phandle, 3);
                    Station_Left_Task.Abort();
                    Station_Right_Task.Abort();
                    Stop_Status_Left = true;
                    Stop_Status_Right = true;
                }

                if (Scram == 1)
                {
                    Scram_State = false;
                }
                //佛山现场复位按键带下电功能
                if (configFile.Regionfoshan == true)
                {
                    //复位左

                    if (Reset_Left == 1 && Start_Left == false)
                    {
                        //复位左工位轴报警
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 0);
                        Thread.Sleep(200);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 0, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 1, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 4, 0);
                        Thread.Sleep(200);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 1);

                        //轴回归原点
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 0, axisParameter.Axis1Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 1, axisParameter.Axis2Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 4, axisParameter.Axis5Speed);
                        if (Station_Left_Task.IsAlive == false)
                        {
                            Station_Left_Task = new Thread(Station_Left);
                            Station_Left_Task.IsBackground = true;
                            Station_Left_Task.Start();
                        }
                        Start_Left = true;
                        Stop_Status_Left = false;
                        int[] AxisList = new int[] { 0, 1, 4 };
                        if (Convert.ToBoolean(Left_Power_tighten) == true)
                        {
                            zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 9, 0);
                            zmcaux.ZAux_Direct_CancelAxisList(Phandle, 3, AxisList, 0);
                            Station_Left_Task.Abort();

                        }

                    }
                    //复位右
                    if (Reset_Right == 1 && Start_Rigth == false)
                    {
                        //复位右工位轴报警
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 0);
                        Thread.Sleep(200);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 2, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 3, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 5, 0);
                        Thread.Sleep(200);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 1);
                        //右工位轴回原点
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 2, axisParameter.Axis3Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 3, axisParameter.Axis4Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 5, axisParameter.Axis6Speed);
                        if (Station_Right_Task.IsAlive == false)
                        {
                            Station_Right_Task = new Thread(Station_Right);
                            Station_Right_Task.IsBackground = true;
                            Station_Right_Task.Start();
                        }
                        Start_Rigth = true;
                        Stop_Status_Right = false;
                        int[] AxisList = new int[] { 2, 3, 5 };
                        if (Convert.ToBoolean(Right_Power_tighten) == true)
                        {
                            zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 13, 0);
                            zmcaux.ZAux_Direct_CancelAxisList(Phandle, 3, AxisList, 0);
                            Station_Right_Task.Abort();
                        }
                    }
                }
                else
                {
                    //复位左
                    if (Reset_Left == 1 && Start_Left == false)
                    {
                        // 复位左工位轴报警
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 0);
                        Thread.Sleep(500);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 0, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 1, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 4, 0);
                        Thread.Sleep(500);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 1);

                        //轴回归原点
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 0, axisParameter.Axis1Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 1, axisParameter.Axis2Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 4, axisParameter.Axis5Speed);
                        if (Station_Left_Task.IsAlive == false)
                        {

                            MotionPoint motionPoint = new MotionPoint();
                            motionPoint.pointStyle = PointStyle.Move;
                            motionPoint.Phandle = Phandle;
                            motionPoint.AxisList = new int[] { 0, 1, 4 };
                            motionPoint.X = axisParameter.Axis1Mpos;
                            motionPoint.Y = axisParameter.Axis2Mpos;
                            motionPoint.Up_Z = 0;
                            Thread.Sleep(500);
                            motionPoint.execute("Left");
                            motionPoint.X = 0;
                            motionPoint.Y = 0;
                            motionPoint.Up_Z = 0;
                            Thread.Sleep(500);
                            motionPoint.execute("Left");

                            autoRunMode = false;



                            Station_Left_Task = new Thread(Station_Left);
                            Station_Left_Task.IsBackground = true;
                            Station_Left_Task.Start();
                        }
                        Start_Left = true;
                        Stop_Status_Left = false;
                    }

                    //复位右
                    if (Reset_Right == 1 && Start_Rigth == false)
                    {
                        //右工位轴报警复位
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 0);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 0);
                        Thread.Sleep(500);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 2, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 3, 0);
                        zmcaux.ZAux_BusCmd_DriveClear(Phandle, 5, 0);
                        Thread.Sleep(500);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 1);
                        zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 1);

                        //右工位轴回原点
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 2, axisParameter.Axis3Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 3, axisParameter.Axis4Speed);
                        zmcaux.ZAux_Direct_SetSpeed(Phandle, 5, axisParameter.Axis6Speed);

                        if (Station_Right_Task.IsAlive == false)
                        {


                            MotionPoint motionPoint = new MotionPoint();
                            motionPoint.pointStyle = PointStyle.Move;
                            motionPoint.Phandle = Phandle;
                            motionPoint.AxisList = new int[] { 2, 3, 5 };
                            motionPoint.X = axisParameter.Axis3Mpos;
                            motionPoint.Y = axisParameter.Axis4Mpos;
                            motionPoint.Up_Z = 0;
                            Thread.Sleep(500);
                            motionPoint.execute("Right");
                            motionPoint.X = 0;
                            motionPoint.Y = 0;
                            motionPoint.Up_Z = 0;
                            Thread.Sleep(500);
                            motionPoint.execute("Right");
                            autoRunMode = false;

                            Station_Right_Task = new Thread(Station_Right);
                            Station_Right_Task.IsBackground = true;
                            Station_Right_Task.Start();
                        }
                        Start_Rigth = true;
                        Stop_Status_Right = false;
                    }
                }


                //黄灯亮
                if (Station_RunLeft == false && Station_RunRight == false && Scram == 1)
                {
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 1, 1);
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 2, 0);
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 0, 0);
                }
                //红灯亮
                if (Scram == 0)
                {
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64, 1);
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 2, 0);
                }
                //绿灯亮
                if ((Station_RunLeft == true || Station_RunRight == true) && Scram == 1)
                {
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64, 0);
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 2, 1);
                    zmcaux.ZAux_Direct_SetOp(Phandle, 64 + 1, 0);
                }


                if (Reset_Left == 0 && Start_Left == true)
                {
                    Start_Left = false;
                }

                if (Reset_Right == 0 && Start_Rigth == true)
                {
                    Start_Rigth = false;
                }
                Thread.Sleep(100);
            }
        }
        private void Station_Left()
        {
            while (SystemRunState)
            {
                uint StartLeft = 0;
                zmcaux.ZAux_Direct_GetIn(Phandle, 64, ref StartLeft);
                bool StartLeft_FromPLC = false;
                if (PLCState == true) StartLeft_FromPLC = (bool)PLC.Read(configFile.PLC_address.StartLeft);
                if (StartLeft == 1 || Station_RunLeftNet == true || (StartLeft_FromPLC == true && Empty_Left == 1))
                {
                    if (PLCState == true)
                    {
                        PLC.Write(configFile.PLC_address.StartLeft, false);
                        PLC.Write(configFile.PLC_address.TestComplete_Left, false);

                    }
                    autoRunMode = true;
                    Thread.Sleep(1000);
                    TestBoard_AutoRun_Left = true;
                    Station_Left_Run();
                    Station_RunLeftNet = false;
                    if (configFile.PLC_Start == true)
                    {
                        PLC.Write(configFile.PLC_address.TestComplete_Left, true);
                        toolStripStatusLabel10.Text = "左测试完成";
                        toolStripStatusLabel10.BackColor = Color.Green;
                    }
                    else
                    {
                        toolStripStatusLabel10.Text = "左测试完成";
                    }
                    TestBoard_AutoRun_Left = false;
                    //给已经连接的所有客户端回复结束
                    if (NetServer.ClientCount > 0)
                    {
                        foreach (KeyValuePair<string, Socket> i in NetServer.SocketList)
                        {
                            NetServer.SendMsg(i.Key, "EndL");
                        }
                    }
                }

                Thread.Sleep(10);
            }
        }
        private void Station_Right()
        {
            while (SystemRunState)
            {
                uint StartRight = 0;
                zmcaux.ZAux_Direct_GetIn(Phandle, 67, ref StartRight);
                bool StartRight_FromPLC = false;
                if (PLCState == true) StartRight_FromPLC = (bool)PLC.Read(configFile.PLC_address.StartRight);
                if (StartRight == 1 || Station_RunRightNet == true || (StartRight_FromPLC == true && Empty_Right == 1))
                {
                    if (PLCState == true)
                    {
                        PLC.Write(configFile.PLC_address.StartRight, false);
                        PLC.Write(configFile.PLC_address.TestComplete_Right, false);
                    }
                    autoRunMode = true;
                    Thread.Sleep(1000);
                    TestBoard_AutoRun_Right = true;
                    Station_Right_Run();
                    Station_RunRightNet = false;
                    //if (PLC.IsConnected == true)
                   
                    if (configFile.PLC_Start == true)
                        {
                        PLC.Write(configFile.PLC_address.TestComplete_Right, true);
                        toolStripStatusLabel12.Text = "右测试完成";
                        toolStripStatusLabel12.BackColor = Color.Green;
                    }
                    else
                    {
                        toolStripStatusLabel12.Text = "右测试完成";
                    }
                    TestBoard_AutoRun_Right = false;
                    //给已经连接的所有客户端回复结束
                    if (NetServer.ClientCount > 0)
                    {
                        foreach (KeyValuePair<string, Socket> i in NetServer.SocketList)
                        {
                            NetServer.SendMsg(i.Key, "EndR");
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }

        private string[] Resolve(string info)
        {
            string[] Result = new string[] { };
            if (info.Contains("CH") || info.Contains("ch"))
            {
                Result = info.Split('\r');
            }
            return Result;
        }

        private void Station_Left_Run()
        {
            DateTime StartTime = DateTime.Now;
            autoRunMode = true;
            Station_RunLeft = true;
            int CodeCount = 0;
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 1);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 1);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 1);

            //左侧工位测量前准备
            HOperatorSet.ClearWindow(hSmartWindowControl1.HalconWindow);
            HOperatorSet.ClearWindow(hSmartWindowControl2.HalconWindow);
            HOperatorSet.ClearWindow(hSmartWindowControl3.HalconWindow);
            HOperatorSet.ClearWindow(hSmartWindowControl4.HalconWindow);
            KeyDisp(hSmartWindowControl10, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl11, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl12, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl13, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");

            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView3);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView3);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView3);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView3);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView3);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView3);


            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView4);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView4);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView4);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView4);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView4);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView4);


            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView5);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView5);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView5);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView5);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView5);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView5);


            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView6);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView6);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView6);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView6);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView6);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView6);

            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label134);
            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label137);
            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label138);
            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label139);
            this.BeginInvoke((Action<ToolStripStatusLabel>)(toolStripStatusLabel => { toolStripStatusLabel.Text = "左测试中"; toolStripStatusLabel.BackColor = Color.White; }), toolStripStatusLabel10);

            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel35);
            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel36);
            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel37);
            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel38);

            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox3);
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox4);
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox5);
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox6);


            this.IR_BOX1.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX1);
            this.IR_BOX2.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX2);
            this.IR_BOX3.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX3);
            this.IR_BOX4.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX4);



            this.Invoke((Action<RichTextBox>)(theRich => { theRich.Clear(); }), richTextBox1);
            this.BeginInvoke((Action<ListBox>)(thelistbox => { thelistbox.Items.Clear(); }), listBox6);

            Image_Screen_Left.Clear();
            Image_Key_Left.Clear();

            TestReslt.TestLeft.Channel1.Clean();
            TestReslt.TestLeft.Channel2.Clean();
            TestReslt.TestLeft.Channel3.Clean();
            TestReslt.TestLeft.Channel4.Clean();

            LeftCodeNumber = 0;
            LeftCodeNumber1 = 0;
            LeftCodeNumber2 = 0;
            LeftCodeNumber3 = 0;

            //左侧工位测量中
            if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints.Count != 0)
            {

                TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Set_Value:3");
                Thread.Sleep(100);
               
                for (int i = 0; i < configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints.Count; i++)
                {
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].SafetyHight = axisParameter.Station_Left_SafetyHight;
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Zoffset = axisParameter.Station_Left_Zoffset;
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].AxisList = new int[] { 0, 1, 4 };
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Phandle = Phandle;
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Code_Value != "") CodeCount++;
                    this.Invoke((Action<RichTextBox>)(theRich => { theRich.AppendText("当前点位:" + configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Name + ": ==================================================================================================\r\n"); }), richTextBox1);
                    NowPoit_Location_Left = i;
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].execute("Left");
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Name == "测静态电流")
                    {
                        List<bool> result = new List<bool>();
                        TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Switch_Current:1");
                        Thread.Sleep(500);
                        for (int k = 0; k < 2; k++)
                        {
                            result.Clear();
                            TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Static_Current");
                            Thread.Sleep(100);
                            if ((TestReslt.TestLeft.Channel1.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestLeft.Channel1.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }
                            if ((TestReslt.TestLeft.Channel2.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestLeft.Channel2.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }

                            if ((TestReslt.TestLeft.Channel3.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestLeft.Channel3.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }

                            if ((TestReslt.TestLeft.Channel4.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestLeft.Channel4.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }
                            if (result.Contains(false) == false) break;
                        }
                        TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Switch_Current:0");
                        Thread.Sleep(500);
                    }

                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Name == "屏幕检测")
                    {
                        if (Shield_ScreenTest == false)
                        {
                            Image_Screen_Left.Clear();
                            Image_Screen_Left.Add(Camera1.GetImageBitMap());
                            Image_Screen_Left.Add(Camera2.GetImageBitMap());
                            Image_Screen_Left.Add(Camera3.GetImageBitMap());
                            Image_Screen_Left.Add(Camera4.GetImageBitMap());
                        }


                    }

                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Name == "按键检测")
                    {
                        if (Shield_KeyTest == false)
                        {

                            Image_Key_Left.Clear();
                            Image_Key_Left.Add(Camera1.GetImageBitMap());
                            Image_Key_Left.Add(Camera2.GetImageBitMap());
                            Image_Key_Left.Add(Camera3.GetImageBitMap());
                            Image_Key_Left.Add(Camera4.GetImageBitMap());

                            YKQ_Test test1 = new YKQ_Test();
                            test1.configFile = configFile;
                            test1.SavaImage = false;
                            test1.listBox = listBox6;
                            test1.TestStation = TestReslt.TestLeft;
                            test1.ykqFeature = ykqFeature;
                            test1.NowProductID = NowProductID;
                            test1.HwindowsList = TestWindow_Left;
                            test1.Image_Screen = Image_Screen_Left;
                            test1.Image_Key = Image_Key_Left;
                            test1.SavaImage = SavaImage;
                            test1.Key_AreaMin = configFile.productList[NowProductID].Key_AreaMin;
                            TestList.Add(test1);
                        }
                    }
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints[i].Code_Value != "" && IRCode_InputMode_Left == true)
                    {
                       
                    }


                }
            }


            //左侧工位测量结束

            string msg1 = "";
            if (TestReslt.TestLeft.Channel1.GetTestResult(configFile.productList[NowProductID], configFile, out msg1, Shield_ScreenTest, Shield_KeyTest, "Left1", CodeCount) == false)
            {
                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label134);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel35);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult1_Left, true);
            }
            else
            {

                if (TestReslt.TestLeft.Channel1.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label134);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel35);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult1_Left, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg1); }), richTextBox3);
            Dsip_testResult(listView3, msg1);
            string msg2 = "";
            if (TestReslt.TestLeft.Channel2.GetTestResult(configFile.productList[NowProductID], configFile, out msg2, Shield_ScreenTest, Shield_KeyTest, "Left2", CodeCount) == false)
            {

                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label137);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel36);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult2_Left, true);
            }
            else
            {

                if (TestReslt.TestLeft.Channel2.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label137);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel36);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult2_Left, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg2); }), richTextBox4);
            Dsip_testResult(listView4, msg2);
            string msg3 = "";
            if (TestReslt.TestLeft.Channel3.GetTestResult(configFile.productList[NowProductID], configFile, out msg3, Shield_ScreenTest, Shield_KeyTest, "Left3", CodeCount) == false)
            {

                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label138);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel37);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult3_Left, true);
            }
            else
            {

                if (TestReslt.TestLeft.Channel3.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label138);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel37);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult3_Left, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg3); }), richTextBox5);
            Dsip_testResult(listView5, msg3);
            string msg4 = "";
            if (TestReslt.TestLeft.Channel4.GetTestResult(configFile.productList[NowProductID], configFile, out msg4, Shield_ScreenTest, Shield_KeyTest, "Left4", CodeCount) == false)
            {

                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label139);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel38);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult4_Left, true);

            }
            else
            {

                if (TestReslt.TestLeft.Channel4.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label139);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel38);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult4_Left, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg4); }), richTextBox6);
            Dsip_testResult(listView6, msg4);
            if (IRCode_InputMode_Left == true)
            {
                while (SP_infoList_Left.Count > 0)
                {
                    Application.DoEvents();
                }
                this.Invoke((Action<CheckBox>)(theBox => { theBox.Checked = false; }), checkBox1);
                Refresh_Motion_Left();
            }


            Station_RunLeft = false;
            ProductTotal.Yield();
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = DateTime.Now.Subtract(StartTime).TotalSeconds.ToString("0") + "秒"; }), label99);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = ProductTotal.ProductCount.ToString(); }), label103);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = ProductTotal.ProductNGCount.ToString(); }), label105);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = ProductTotal.Yield(); }), label107);

            DisplayNG_Chart(chart1);
        }

        private void Station_Right_Run()
        {
            //右侧工位测量前准备
            autoRunMode = true;
            DateTime StartTime = DateTime.Now;
            Station_RunRight = true;
            int CodeCount = 0;

            HOperatorSet.ClearWindow(hSmartWindowControl5.HalconWindow);
            HOperatorSet.ClearWindow(hSmartWindowControl6.HalconWindow);
            HOperatorSet.ClearWindow(hSmartWindowControl7.HalconWindow);
            HOperatorSet.ClearWindow(hSmartWindowControl8.HalconWindow);
            KeyDisp(hSmartWindowControl14, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl15, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl16, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl17, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");

            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView7);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView7);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView7);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView7);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView7);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView7);

            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView8);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView8);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView8);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView8);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView8);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView8);

            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView9);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView9);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView9);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView9);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView9);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView9);

            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[0].SubItems[1].Text = "0mA"; theListView.Items[0].BackColor = Color.White; }), listView10);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[1].SubItems[1].Text = "0mA"; theListView.Items[1].BackColor = Color.White; }), listView10);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[2].SubItems[1].Text = "0uA"; theListView.Items[2].BackColor = Color.White; }), listView10);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[3].SubItems[1].Text = "0KHz"; theListView.Items[3].BackColor = Color.White; }), listView10);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[4].SubItems[1].Text = "待测试"; theListView.Items[4].BackColor = Color.White; }), listView10);
            this.BeginInvoke((Action<ListView>)(theListView => { theListView.Items[5].SubItems[1].Text = "待测试"; theListView.Items[5].BackColor = Color.White; theListView.SelectedItems.Clear(); }), listView10);

            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label140);
            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label141);
            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label142);
            this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "测试中"; }), label143);
            this.BeginInvoke((Action<ToolStripStatusLabel>)(toolStripStatusLabel => { toolStripStatusLabel.Text = "右测试中"; toolStripStatusLabel12.BackColor = Color.White; }), toolStripStatusLabel12);

            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox7);
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox8);
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox9);
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.Clear(); }), richTextBox10);

            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel39);
            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel40);
            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel41);
            this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Yellow; }), panel42);

            this.Invoke((Action<RichTextBox>)(theRich => { theRich.Clear(); }), richTextBox2);

            TestReslt.TestRight.Channel1.Clean();
            TestReslt.TestRight.Channel2.Clean();
            TestReslt.TestRight.Channel3.Clean();
            TestReslt.TestRight.Channel4.Clean();

            Image_Screen_Right.Clear();
            Image_Key_Right.Clear();

            this.IR_BOX5.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX5);
            this.IR_BOX6.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX6);
            this.IR_BOX7.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX7);
            this.IR_BOX8.BeginInvoke((Action<ListBox>)(theBox => { theBox.Items.Clear(); }), IR_BOX8);

            RightCodeNumber = 0;
            RightCodeNumber1 = 0;
            RightCodeNumber2 = 0;
            RightCodeNumber3 = 0;


            //右侧工位测量中
            if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints.Count != 0)
            {
                TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Set_Value:3");
                Thread.Sleep(100);
                for (int i = 0; i < configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints.Count; i++)
                {

                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].SafetyHight = axisParameter.Station_Right_SafetyHight;
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Zoffset = axisParameter.Station_Right_Zoffset;
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].AxisList = new int[] { 2, 3, 5 };
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Phandle = Phandle;
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Code_Value != "") CodeCount++;
                    this.Invoke((Action<RichTextBox>)(theRich => { theRich.AppendText("当前点位:" + motioncontrol_Right.motionPoints[i].Name + ": ==================================================================================================\r\n"); }), richTextBox2);
                    NowPoit_Location_Right = i;
                    configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].execute("Right");
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Name == "测静态电流")
                    {
                        List<bool> result = new List<bool>();

                        TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Switch_Current:1");
                        Thread.Sleep(500);
                        for (int k = 0; k < 2; k++)
                        {
                            result.Clear();
                            TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Static_Current");
                            Thread.Sleep(500);
                            if ((TestReslt.TestRight.Channel1.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestRight.Channel1.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }


                            if ((TestReslt.TestRight.Channel2.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestRight.Channel2.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }

                            if ((TestReslt.TestRight.Channel3.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestRight.Channel3.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }

                            if ((TestReslt.TestRight.Channel4.QuiescentCurrent <= configFile.productList[NowProductID].Config.QuiescentCurrentMax) && (TestReslt.TestRight.Channel4.QuiescentCurrent > configFile.productList[NowProductID].Config.QuiescentCurrentMin))
                            {
                                result.Add(true);
                            }
                            else
                            {
                                result.Add(false);
                            }

                            if (result.Contains(false) == false) break;

                        }
                        Thread.Sleep(500);
                        TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Switch_Current:0");
                    }
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Name == "屏幕检测")
                    {
                        if (Shield_ScreenTest == false)
                        {

                            Image_Screen_Right.Clear();
                            Image_Screen_Right.Add(Camera5.GetImageBitMap());
                            Image_Screen_Right.Add(Camera6.GetImageBitMap());
                            Image_Screen_Right.Add(Camera7.GetImageBitMap());
                            Image_Screen_Right.Add(Camera8.GetImageBitMap());




                        }
                    }
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Name == "按键检测")
                    {
                        if (Shield_KeyTest == false)
                        {

                            Image_Key_Right.Clear();
                            Image_Key_Right.Add(Camera5.GetImageBitMap());
                            Image_Key_Right.Add(Camera6.GetImageBitMap());
                            Image_Key_Right.Add(Camera7.GetImageBitMap());
                            Image_Key_Right.Add(Camera8.GetImageBitMap());

                            YKQ_Test test1 = new YKQ_Test();
                            test1.configFile = configFile;
                            test1.SavaImage = false;
                            test1.listBox = listBox7;
                            test1.TestStation = TestReslt.TestRight;
                            test1.ykqFeature = ykqFeature;
                            test1.NowProductID = NowProductID;
                            test1.HwindowsList = TestWindow_Right;
                            test1.Image_Screen = Image_Screen_Right;
                            test1.Image_Key = Image_Key_Right;
                            test1.SavaImage = SavaImage;
                            test1.Key_AreaMin = configFile.productList[NowProductID].Key_AreaMin;
                            TestList.Add(test1);


                        }
                    }
                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints[i].Code_Value != "" && IRCode_InputMode_Right == true)
                    {

                    }
                }
            }
            //右侧工位测量结束



            string msg1 = "";

            if (TestReslt.TestRight.Channel1.GetTestResult(configFile.productList[NowProductID], configFile, out msg1, Shield_ScreenTest, Shield_KeyTest, "Right1", CodeCount) == false)
            {
                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label140);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel39);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult1_Right, true);
            }
            else
            {
                if (TestReslt.TestRight.Channel1.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label140);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel39);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult1_Right, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg1); }), richTextBox7);
            Dsip_testResult(listView7, msg1);
            string msg2 = "";
            if (TestReslt.TestRight.Channel2.GetTestResult(configFile.productList[NowProductID], configFile, out msg2, Shield_ScreenTest, Shield_KeyTest, "Right2", CodeCount) == false)
            {

                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label141);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel40);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult2_Right, true);
            }
            else
            {

                if (TestReslt.TestRight.Channel2.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label141);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel40);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult2_Right, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg2); }), richTextBox9);
            Dsip_testResult(listView8, msg2);
            string msg3 = "";
            if (TestReslt.TestRight.Channel3.GetTestResult(configFile.productList[NowProductID], configFile, out msg3, Shield_ScreenTest, Shield_KeyTest, "Right3", CodeCount) == false)
            {

                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label142);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel41);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult3_Right, true);

            }
            else
            {

                if (TestReslt.TestRight.Channel3.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label142);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel41);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult3_Right, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg3); }), richTextBox10);
            Dsip_testResult(listView9, msg3);
            string msg4 = "";
            if (TestReslt.TestRight.Channel4.GetTestResult(configFile.productList[NowProductID], configFile, out msg4, Shield_ScreenTest, Shield_KeyTest, "Right4", CodeCount) == false)
            {

                ProductTotal.OKAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品OK"; }), label143);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Green; }), panel42);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult4_Right, true);
            }
            else
            {

                if (TestReslt.TestRight.Channel4.ProductIsEmpty == false) ProductTotal.NGAdd();
                this.BeginInvoke((Action<Label>)(thelabel => { thelabel.Text = "产品NG"; }), label143);
                this.BeginInvoke((Action<Panel>)(thePanel => { thePanel.BackColor = Color.Red; }), panel42);
                if (PLCState == true) PLC.Write(configFile.PLC_address.TestReult4_Right, false);
            }
            this.BeginInvoke((Action<RichTextBox>)(thebox => { thebox.AppendText(msg4); }), richTextBox8);
            Dsip_testResult(listView10, msg4);
            if (IRCode_InputMode_Right == true)
            {
                while (SP_infoList_Right.Count > 0)
                {
                    Application.DoEvents();
                }
                this.Invoke((Action<CheckBox>)(theBox => { theBox.Checked = false; }), checkBox4);
                Refresh_Motion_Right();

            }
            Station_RunRight = false;
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = DateTime.Now.Subtract(StartTime).TotalSeconds.ToString("0") + "秒"; }), label101);

            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = ProductTotal.ProductCount.ToString(); }), label103);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = ProductTotal.ProductNGCount.ToString(); }), label105);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = ProductTotal.Yield(); }), label107);

            DisplayNG_Chart(chart1);
        }

        private void Refresh_Motion_Left()
        {

            try
            {

                    if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints.Count > 0)
                    {
                        motioncontrol_Left = configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left;
                        //切换运动轨迹
                        if (listView1.InvokeRequired == false)
                        {
                            listView1.Items.Clear();
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView1);
                        }
                        for (int i = 0; i < motioncontrol_Left.motionPoints.Count; i++)
                        {
                            ListViewItem listViewItem = new ListViewItem();
                            listViewItem.Text = motioncontrol_Left.motionPoints[i].Name;
                            switch (motioncontrol_Left.motionPoints[i].pointStyle)
                            {
                                case PointStyle.IOContrlo:
                                    listViewItem.SubItems.Add("IO控制");
                                    break;
                                case PointStyle.KeyTest:
                                    listViewItem.SubItems.Add("按键测试");
                                    break;
                                case PointStyle.Camera:
                                    listViewItem.SubItems.Add("相机拍照");
                                    break;
                                case PointStyle.KeyTest_IO:
                                    listViewItem.SubItems.Add("按键测试&气缸动作");
                                    break;
                                case PointStyle.Move:
                                    listViewItem.SubItems.Add("移动");
                                    break;
                                case PointStyle.Wait:
                                    listViewItem.SubItems.Add("等待");
                                    break;

                            }
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Code_Value);
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].X.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Y.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Up_Z.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Down_Z.ToString());
                            if (listView1.InvokeRequired == false)
                            {
                                listView1.Items.Add(listViewItem);
                            }
                            else
                            {
                                this.Invoke((Action<ListView>)(theView => { theView.Items.Add(listViewItem); }), listView1);
                            }
                        }

                    }
                    else
                    {
                        if (listView1.InvokeRequired == false)
                        {
                            listView1.Items.Clear();
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView1);
                        }
                    }

            }
            catch (Exception ex)
            {
                listView1.Items.Clear();
            }
        }

        private void Refresh_Motion_Right()
        {
            try
            {
                if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right.motionPoints.Count > 0)
                {
                    motioncontrol_Right = configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Right;
                    if (listView2.InvokeRequired == false)
                    {
                        listView2.Items.Clear();
                    }
                    else
                    {
                        this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView2);
                    }

                    for (int i = 0; i < motioncontrol_Right.motionPoints.Count; i++)
                    {
                        ListViewItem listViewItem = new ListViewItem();
                        listViewItem.Text = motioncontrol_Right.motionPoints[i].Name;
                        switch (motioncontrol_Right.motionPoints[i].pointStyle)
                        {
                            case PointStyle.IOContrlo:
                                listViewItem.SubItems.Add("IO控制");
                                break;
                            case PointStyle.KeyTest:
                                listViewItem.SubItems.Add("按键测试");
                                break;
                            case PointStyle.Camera:
                                listViewItem.SubItems.Add("相机拍照");
                                break;
                            case PointStyle.KeyTest_IO:
                                listViewItem.SubItems.Add("按键测试&气缸动作");
                                break;
                            case PointStyle.Move:
                                listViewItem.SubItems.Add("移动");
                                break;
                            case PointStyle.Wait:
                                listViewItem.SubItems.Add("等待");
                                break;

                        }

                        listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Code_Value);
                        listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].X.ToString());
                        listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Y.ToString());
                        listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Up_Z.ToString());
                        listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Down_Z.ToString());

                        if (listView2.InvokeRequired == false)
                        {
                            listView2.Items.Add(listViewItem);
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Add(listViewItem); }), listView2);
                        }
                    }

                }
                else
                {
                    if (listView2.InvokeRequired == false)
                    {
                        listView2.Items.Clear();
                    }
                    else
                    {
                        this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView2);
                    }
                }
            }
            catch (Exception ex)
            {
                listView2.Items.Clear();
            }
        }


        private void SaveConfig()
        {
            try
            {
                string Json_Config = JsonConvert.SerializeObject(configFile, Formatting.Indented);
                FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\Config.json", FileMode.Create, FileAccess.Write);
                StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.UTF8);
                if (Json_Config != "")
                {
                    streamWriter1.Write(Json_Config);
                }
                streamWriter1.Close();
                fileStream1.Close();

            }
            catch
            {
                MessageBox.Show("保存参数异常");
            }
        }
        private void savaMotionControl()
        {
            string Json_MotionControl_Left = JsonConvert.SerializeObject(motioncontrol_Left);
            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Config") == false)
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\Config");
            }
            FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\MotionControl_Left.json", FileMode.Create, FileAccess.Write);
            StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.Default);
            streamWriter1.Write(Json_MotionControl_Left);
            streamWriter1.Close();
            fileStream1.Close();

            string Json_MotionControl_Right = JsonConvert.SerializeObject(motioncontrol_Right);
            FileStream fileStream2 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\MotionControl_Right.json", FileMode.Create, FileAccess.Write);
            StreamWriter streamWriter2 = new StreamWriter(fileStream2, Encoding.Default);
            streamWriter2.Write(Json_MotionControl_Right);
            streamWriter2.Close();
            fileStream2.Close();


        }

        private void Clean_Dir(string dir)
        {
            if (Directory.Exists(dir) == true)
            {
                string[] fileList = Directory.GetFiles(dir);
                if (fileList.Length > 0)
                {
                    for (int i = 0; i < fileList.Length; i++)
                    {
                        File.Delete(fileList[i]);
                    }
                }
            }

        }



        private ScreenResult ScreenTest(HSmartWindowControl hSmartWindow, Bitmap image, int imgindex, ListBox listBox, out bool IsEmpty)
        {
            IsEmpty = false;
            ScreenResult testResult = new ScreenResult();
            HObject Image_H = new HObject();
            HTuple ang = new HTuple();
            HTuple hTuple = new HTuple();
            HTuple Hwindos = new HTuple(hSmartWindow.HalconWindow);
            HTuple w, h, Test_Result;
            HObject ROI = new HObject();
            HObject ScreenModelROI = new HObject();
            HObject Region_H = new HObject();
            HTuple ModelID = new HTuple();
            HObject Result_Region = new HObject();
            HTuple NG_Result = new HTuple();
            HTuple Count_obj = new HTuple();
            HObject SelectedRegions = new HObject();
            HObject ImageRotate = new HObject();
            HObject NG_Region = new HObject();
            HObject YJImage_Em = new HObject();
            HObject YJImage = new HObject();
            int NGcount = 0;
            string LastDriveNo = GetLastDriveNo();
            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\ModelID") == true)
            {


                if (image != null)
                {
                    ImageConvert.Bitmap2HObjectS(image, out Image_H);
                    HOperatorSet.RotateImage(Image_H, out ImageRotate, 90, "constant");
                    try
                    {
                        if (configFile.productList[NowProductID].P_Style == Product.Product_Style.RomoteControl_White)
                        {
                            algorithm.GetScreen(ImageRotate, out YJImage, out YJImage_Em, out ang);
                        }

                        if (configFile.productList[NowProductID].P_Style == Product.Product_Style.RomoteControl_black)
                        {
                            HOperatorSet.ReadShapeModel(Directory.GetCurrentDirectory() + @"\Model\Black_FindModel", out HTuple ScreenFindModel);
                            algorithm.Get_Screen_Black(ImageRotate, out YJImage, out YJImage_Em, ScreenFindModel, out ang);
                        }

                        testResult.ScreenDisp = true;
                        //屏幕型号分类

                        HOperatorSet.GenEmptyRegion(out HObject out_NG_Region);
                        if (YJImage_Em != null && configFile.productList[NowProductID].P_Style == Product.Product_Style.RomoteControl_White)
                        {

                        }


                        hSmartWindow.HalconWindow.ClearWindow();
                        HOperatorSet.GenEmptyObj(out NG_Region);
                        HOperatorSet.GetImageSize(YJImage_Em, out w, out h);
                        HOperatorSet.SetPart(hSmartWindow.HalconWindow, 0, 0, h - 1, w - 1);
                        HOperatorSet.DispObj(YJImage_Em, hSmartWindow.HalconWindow);
                        HOperatorSet.SetColor(hSmartWindow.HalconWindow, "red");

                        if (ykqFeature.ScreenFeatures.Count > 0)
                        {
                            for (int i = 0; i < ykqFeature.ScreenFeatures.Count; i++)
                            {
                                algorithm.Test_Screen(YJImage_Em, ykqFeature.ScreenFeatures[i].FeatureROI, ykqFeature.ScreenFeatures[i].FeatureRegion, out Result_Region, 100, ykqFeature.ScreenFeatures[i].Model, out Test_Result);
                                if (Test_Result == 2)
                                {
                                    NGcount++;
                                    HOperatorSet.DispObj(Result_Region, hSmartWindow.HalconWindow);
                                    break;
                                }

                            }

                        }

                        Console.WriteLine("屏幕检测显示结果：" + NGcount);
                        algorithm.set_display_font(hSmartWindow.HalconWindow, 15, "mono", "true", "false");
                        if (NGcount > 0)
                        {
                            if (Directory.Exists(LastDriveNo + @":\SaveImage\ScreenTest\" + DateTime.Now.ToString("yyyyMMdd") + @"\" + configFile.productList[NowProductID].Model + @"\NGImage") == false)
                            {
                                Directory.CreateDirectory(LastDriveNo + @":\SaveImage\ScreenTest\" + DateTime.Now.ToString("yyyyMMdd") + @"\" + configFile.productList[NowProductID].Model + @"\NGImage");
                            }

                            HOperatorSet.WriteImage(YJImage_Em, "bmp", 0, LastDriveNo + @":\SaveImage\ScreenTest\" + DateTime.Now.ToString("yyyyMMdd") + @"\" + configFile.productList[NowProductID].Model + @"\NGImage\" + DateTime.Now.ToString("HHmmss") + SaveNG_ScreenCount + ".bmp");
                            testResult.ScreenClass = false;
                            algorithm.disp_message(hSmartWindow.HalconWindow, "NG", "window", 0, 0, "red", "true");
                            HOperatorSet.DispRegion(out_NG_Region, hSmartWindow.HalconWindow);
                        }
                        else
                        {
                            testResult.ScreenClass = true;
                            algorithm.disp_message(hSmartWindow.HalconWindow, "OK", "window", 0, 0, "green", "true");

                        }

                    }
                    catch (Exception error)
                    {
                        Console.WriteLine("屏幕测试异常" + error.Message);
                        testResult.ScreenClass = false;
                        algorithm.disp_message(hSmartWindow.HalconWindow, "屏幕测试异常", "window", 0, 0, "red", "true");
                        IsEmpty = true;
                    }
                }
            }

            //释放掉所有资源
            Image_H.Dispose();
            ang.Dispose();
            hTuple.Dispose();
            ROI.Dispose();
            ScreenModelROI.Dispose();
            Region_H.Dispose();
            ModelID.Dispose();
            Result_Region.Dispose();

            NG_Result.Dispose();
            Count_obj.Dispose();
            SelectedRegions.Dispose();
            ImageRotate.Dispose();
            NG_Region.Dispose();
            YJImage.Dispose();
            YJImage_Em.Dispose();
            return testResult;

        }

        private string GetLastDriveNo()
        {
            DriveInfo[] driveInfos = DriveInfo.GetDrives();
            List<DriveInfo> drives_List = new List<DriveInfo>();
            for (int i = 0; i < driveInfos.Length; i++)
            {
                if (driveInfos[i].DriveType == DriveType.Fixed) drives_List.Add(driveInfos[i]);
            }
            return drives_List[drives_List.Count - 1].Name.Substring(0, 1);
        }

        private void CameraContinousImage(HikVisionCamera camera, PictureBox pictureBox)
        {
            while (continuousImage)
            {
                pictureBox.Invoke((Action<PictureBox>)(thePicBox => { thePicBox.Image = camera.GetImageBitMap(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; }), pictureBox);
                Thread.Sleep(100);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
                configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].AxisList = new int[] { 2, 3, 5 };
                configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Phandle = Phandle;
                configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].execute("Right");
            }
        }


        private void Form1_Resize(object sender, EventArgs e)
        {
            autoZone.ReWinformLayout(this.Width, this.Height, this);
            listView1.Columns[0].Width = Convert.ToInt16(listView1.Width * 0.15);
            listView1.Columns[1].Width = Convert.ToInt16(listView1.Width * 0.15);
            listView1.Columns[2].Width = Convert.ToInt16(listView1.Width * 0.10);
            listView1.Columns[3].Width = Convert.ToInt16(listView1.Width * 0.15);
            listView1.Columns[4].Width = Convert.ToInt16(listView1.Width * 0.15);
            listView1.Columns[5].Width = Convert.ToInt16(listView1.Width * 0.15);
            listView1.Columns[6].Width = Convert.ToInt16(listView1.Width * 0.15);

            listView2.Columns[0].Width = Convert.ToInt16(listView2.Width * 0.15);
            listView2.Columns[1].Width = Convert.ToInt16(listView2.Width * 0.15);
            listView2.Columns[2].Width = Convert.ToInt16(listView2.Width * 0.10);
            listView2.Columns[3].Width = Convert.ToInt16(listView2.Width * 0.15);
            listView2.Columns[4].Width = Convert.ToInt16(listView2.Width * 0.15);
            listView2.Columns[5].Width = Convert.ToInt16(listView2.Width * 0.15);
            listView2.Columns[6].Width = Convert.ToInt16(listView2.Width * 0.15);

            listView3.Columns[0].Width = Convert.ToInt16(listView3.Width * 0.5);
            listView3.Columns[1].Width = Convert.ToInt16(listView3.Width * 0.5);

            listView4.Columns[0].Width = Convert.ToInt16(listView4.Width * 0.5);
            listView4.Columns[1].Width = Convert.ToInt16(listView4.Width * 0.5);

            listView5.Columns[0].Width = Convert.ToInt16(listView5.Width * 0.5);
            listView5.Columns[1].Width = Convert.ToInt16(listView5.Width * 0.5);

            listView6.Columns[0].Width = Convert.ToInt16(listView6.Width * 0.5);
            listView6.Columns[1].Width = Convert.ToInt16(listView6.Width * 0.5);

            listView7.Columns[0].Width = Convert.ToInt16(listView7.Width * 0.5);
            listView7.Columns[1].Width = Convert.ToInt16(listView7.Width * 0.5);

            listView8.Columns[0].Width = Convert.ToInt16(listView8.Width * 0.5);
            listView8.Columns[1].Width = Convert.ToInt16(listView8.Width * 0.5);

            listView9.Columns[0].Width = Convert.ToInt16(listView9.Width * 0.5);
            listView9.Columns[1].Width = Convert.ToInt16(listView9.Width * 0.5);

            listView10.Columns[0].Width = Convert.ToInt16(listView10.Width * 0.5);
            listView10.Columns[1].Width = Convert.ToInt16(listView10.Width * 0.5);





        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {

                SaveDataToTxtBox(textBox75, ref configFile.SavaImageTime);
                //将轴参数写入控制器
                SaveAxisParameter();
                ApplyAxisParameter(axisParameter);

                string JsonTxt = JsonConvert.SerializeObject(axisParameter, Formatting.Indented);
                if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Config") == false)
                {
                    Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\Config");
                }

                FileStream fileStream = new FileStream(Directory.GetCurrentDirectory() + @"\Config\axisParameter.json", FileMode.Create, FileAccess.Write);
                StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.Default);
                streamWriter.Write(JsonTxt);
                streamWriter.Close();
                fileStream.Close();


                //保存相机参数


                try
                {
                    float Camera_ExposureTime = Convert.ToSingle(textBox25.Text);

                    switch (comboBox3.SelectedIndex)
                    {
                        case 0:
                            Camera1.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera1ExposureTime = Camera_ExposureTime;
                            break;
                        case 1:
                            Camera2.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera2ExposureTime = Camera_ExposureTime;
                            break;
                        case 2:
                            Camera3.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera3ExposureTime = Camera_ExposureTime;
                            break;
                        case 3:
                            Camera4.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera4ExposureTime = Camera_ExposureTime;
                            break;
                        case 4:
                            Camera5.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera5ExposureTime = Camera_ExposureTime;
                            break;
                        case 5:
                            Camera6.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera6ExposureTime = Camera_ExposureTime;
                            break;
                        case 6:
                            Camera7.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera7ExposureTime = Camera_ExposureTime;
                            break;
                        case 7:
                            Camera8.m_MyCamera.SetFloatValue("ExposureTime", Camera_ExposureTime);
                            configFile.productList[NowProductID].Config.Camera8ExposureTime = Camera_ExposureTime;
                            break;
                    }
                }
                catch
                {
                    MessageBox.Show("相机参数异常", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }


        }
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {

                case Keys.A:
                    this.pictureBox4_MouseUp(null, null);
                    this.pictureBox16_MouseUp(null, null);
                    break;
                case Keys.W:
                    this.pictureBox3_MouseUp(null, null);
                    this.pictureBox11_MouseUp(null, null);
                    break;
                case Keys.D:
                    this.pictureBox2_MouseUp(null, null);
                    this.pictureBox14_MouseUp(null, null);
                    break;
                case Keys.S:
                    this.pictureBox5_MouseUp(null, null);
                    this.pictureBox17_MouseUp(null, null);
                    break;
                case Keys.Q:
                    this.pictureBox7_MouseUp(null, null);
                    this.pictureBox13_MouseUp(null, null);
                    break;
                case Keys.E:
                    this.pictureBox6_MouseUp(null, null);
                    this.pictureBox12_MouseUp(null, null);
                    break;
                case Keys.R:
                    this.button17_MouseUp(null, null);
                    break;
                case Keys.H:
                    this.pictureBox9_MouseUp(null, null);
                    this.pictureBox18_MouseUp(null, null);
                    break;
                case Keys.Space:
                    this.pictureBox4_MouseUp(null, null);
                    this.pictureBox16_MouseUp(null, null);
                    this.pictureBox3_MouseUp(null, null);
                    this.pictureBox11_MouseUp(null, null);
                    this.pictureBox2_MouseUp(null, null);
                    this.pictureBox14_MouseUp(null, null);
                    this.pictureBox5_MouseUp(null, null);
                    this.pictureBox17_MouseUp(null, null);
                    this.pictureBox7_MouseUp(null, null);
                    this.pictureBox13_MouseUp(null, null);
                    this.pictureBox6_MouseUp(null, null);
                    this.pictureBox12_MouseUp(null, null);
                    this.button17_MouseUp(null, null);
                    this.pictureBox9_MouseUp(null, null);
                    this.pictureBox18_MouseUp(null, null);
                    break;

            }
            return;
        }

        private void pictureBox4_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox4.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 0, -1);
        }

        private void pictureBox4_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox4.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 0, 3);
        }

        private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox2.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 0, 1);
        }

        private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox2.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 0, 3);
        }

        private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox3.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 1, -1);
        }

        private void pictureBox3_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox3.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 1, 3);
        }

        private void pictureBox5_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox5.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 1, 1);
        }

        private void pictureBox5_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox5.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 1, 3);
        }

        private void pictureBox7_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox7.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 4, 1);
        }

        private void pictureBox7_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox7.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 4, 3);
        }

        private void pictureBox6_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox6.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 4, -1);
        }

        private void pictureBox6_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox6.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 4, 3);
        }

        private void button15_MouseDown(object sender, MouseEventArgs e)
        {
            button15.BackColor = Color.White;
        }

        private void button15_MouseUp(object sender, MouseEventArgs e)
        {
            button15.BackColor = Color.Silver;
        }

        private void button17_MouseDown(object sender, MouseEventArgs e)
        {
            button17.BackColor = Color.White;
        }

        private void button17_MouseUp(object sender, MouseEventArgs e)
        {
            button17.BackColor = Color.Silver;
        }


        private void button14_MouseDown(object sender, MouseEventArgs e)
        {
            button14.BackColor = Color.White;
        }

        private void button14_MouseUp(object sender, MouseEventArgs e)
        {
            button14.BackColor = Color.Silver;
        }

        private void button16_MouseDown(object sender, MouseEventArgs e)
        {
            button16.BackColor = Color.White;
        }

        private void button16_MouseUp(object sender, MouseEventArgs e)
        {
            button16.BackColor = Color.Silver;
        }

        private void pictureBox8_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox8.BackColor = Color.White;
        }

        private void pictureBox8_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox8.BackColor = Color.Silver;
        }

        private void pictureBox9_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox9.BackColor = Color.White;
        }

        private void pictureBox9_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox9.BackColor = Color.Silver;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            DialogResult Reslut = MessageBox.Show("确定是否将该位置是否设置未坐标零点", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (Reslut == DialogResult.OK)
            {
                configFile.Amendment_X_Left = axisParameter.Axis1Mpos;
                configFile.Amendment_Y_Left = axisParameter.Axis2Mpos;
                configFile.Amendment_Z_Left = axisParameter.Axis5Mpos;
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 0);
            Thread.Sleep(500);
            zmcaux.ZAux_BusCmd_DriveClear(Phandle, 0, 0);
            zmcaux.ZAux_BusCmd_DriveClear(Phandle, 1, 0);
            zmcaux.ZAux_BusCmd_DriveClear(Phandle, 4, 0);
            Thread.Sleep(500);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 1);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 1);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 1);
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            if (comboBox11.SelectedIndex > -1)
            {
                MotionPoint motionPoint = new MotionPoint();
                motionPoint.X = axisParameter.Axis1Mpos;
                motionPoint.Y = axisParameter.Axis2Mpos;
                motionPoint.Down_Z = axisParameter.Axis5Mpos;
                Form2 form2 = new Form2(motionPoint, Code_Station_Left);
                form2.ShowDialog();
                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Text = form2.point.Name;
                switch (form2.point.pointStyle)
                {
                    case PointStyle.IOContrlo:
                        listViewItem.SubItems.Add("IO控制");
                        break;
                    case PointStyle.KeyTest:
                        listViewItem.SubItems.Add("按键测试");
                        break;
                    case PointStyle.Camera:
                        listViewItem.SubItems.Add("相机拍照");
                        break;
                    case PointStyle.KeyTest_IO:
                        listViewItem.SubItems.Add("按键测试&气缸动作");
                        break;
                    case PointStyle.Move:
                        listViewItem.SubItems.Add("移动");
                        break;
                    case PointStyle.Wait:
                        listViewItem.SubItems.Add("等待");
                        break;

                }

                listViewItem.SubItems.Add(form2.point.Code_Value);
                listViewItem.SubItems.Add(form2.point.X.ToString());
                listViewItem.SubItems.Add(form2.point.Y.ToString());
                listViewItem.SubItems.Add(form2.point.Up_Z.ToString());
                listViewItem.SubItems.Add(form2.point.Down_Z.ToString());
                listView1.Items.Add(listViewItem);
                configFile.MotionControl_List[comboBox11.SelectedItem.ToString()].motioncontrol_Left.motionPoints.Add(form2.point);
            }


        }

        private void AxisEndOf(int[] AxisList)
        {
            int AxisXState = 0;
            int AxisYState = 0;
            int AxisZState = 0;
            while (true)
            {
                zmcaux.ZAux_Direct_GetIfIdle(Phandle, AxisList[0], ref AxisXState);
                zmcaux.ZAux_Direct_GetIfIdle(Phandle, AxisList[1], ref AxisYState);
                zmcaux.ZAux_Direct_GetIfIdle(Phandle, AxisList[2], ref AxisZState);

                if (AxisXState == -1 && AxisYState == -1 && AxisZState == -1)
                {
                    break;
                }
                Application.DoEvents();
            }

        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
            try
            {
                pictureBox9.BackColor = Color.LawnGreen;
                int[] AxisList = new int[] { 0, 1, 4 };
                float[] Point = new float[] { configFile.LeftHomeX, configFile.LeftHomeY, configFile.LeftHomeZ };
                zmcaux.ZAux_Direct_MoveAbs(Phandle, 3, AxisList, Point);
                AxisEndOf(AxisList);
                pictureBox9.BackColor = Color.Silver;
                autoRunMode = false;

            }
            catch
            {
                MessageBox.Show("运动控制卡异常", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void panel8_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tabPage5_Click(object sender, EventArgs e)
        {

        }

        private void checkBox21_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void pictureBox18_Click(object sender, EventArgs e)
        {
            try
            {
                pictureBox18.BackColor = Color.LawnGreen;
                int[] AxisList = new int[] { 2, 3, 5 };
                float[] Point = new float[] { configFile.RightHomeX, configFile.RightHomeY, configFile.RightHomeZ };
                zmcaux.ZAux_Direct_MoveAbs(Phandle, 3, AxisList, Point);
                AxisEndOf(AxisList);
                autoRunMode = false;
                pictureBox18.BackColor = Color.Silver;
            }
            catch
            {
                MessageBox.Show("运动控制卡异常", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void pictureBox18_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox18.BackColor = Color.White;
        }

        private void pictureBox18_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox18.BackColor = Color.Silver;
        }



        private void pictureBox16_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox16.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 2, 1);
        }

        private void pictureBox16_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox16.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 2, 3);
        }

        private void pictureBox14_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox14.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 2, -1);
        }

        private void pictureBox14_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox14.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 2, 3);
        }



        private void pictureBox11_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox11.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 3, -1);
        }

        private void pictureBox11_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox11.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 3, 3);
        }

        private void pictureBox17_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox17.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 3, 1);
        }

        private void pictureBox17_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox17.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 3, 3);
        }

        private void pictureBox13_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox13.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 5, 1);
        }

        private void pictureBox13_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox13.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 5, 3);
        }

        private void pictureBox12_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox12.BackColor = Color.White;
            zmcaux.ZAux_Direct_Single_Vmove(Phandle, 5, -1);
        }

        private void pictureBox12_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox12.BackColor = Color.Silver;
            zmcaux.ZAux_Direct_Single_Cancel(Phandle, 5, 3);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 0);
            Thread.Sleep(200);
            zmcaux.ZAux_BusCmd_DriveClear(Phandle, 2, 0);
            zmcaux.ZAux_BusCmd_DriveClear(Phandle, 3, 0);
            zmcaux.ZAux_BusCmd_DriveClear(Phandle, 5, 0);
            Thread.Sleep(200);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 1);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 1);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 1);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    if (GetImage_task_Left == null)
                    {
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera1, pictureBox10));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Left);
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera1, pictureBox10));

                    }
                    break;
                case 1:
                    if (GetImage_task_Left == null)
                    {
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera2, pictureBox10));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Left);
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera2, pictureBox10));

                    }
                    break;
                case 2:
                    if (GetImage_task_Left == null)
                    {
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera3, pictureBox10));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Left);
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera3, pictureBox10));

                    }
                    break;
                case 3:
                    if (GetImage_task_Left == null)
                    {
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera4, pictureBox10));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Left);
                        continuousImage = true;
                        GetImage_task_Left = Task.Run(() => CameraContinousImage(Camera4, pictureBox10));

                    }
                    break;

            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            DialogResult result = MessageBox.Show("是否退出软件", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (result == DialogResult.OK)
            {
                SystemRunState = false;
                Camera1.Close();
                Camera2.Close();
                Camera3.Close();
                Camera4.Close();
                Camera5.Close();
                Camera6.Close();
                Camera7.Close();
                Camera8.Close();
            }
            else
            {
                e.Cancel = true;
            }


            while (IOStatus_Task.Status == TaskStatus.Running || AxisState_task.Status == TaskStatus.Running)
            {
                Application.DoEvents();
            }

            try
            {
                zmcaux.ZAux_Close(Phandle);
            }
            catch
            {

            }


            continuousImage = false;
            savaMotionControl();
            Thread.Sleep(500);
            SaveConfig();

        }


        private void TestBoard_Left_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            //try
            //{
            //    KeyDown_Left = false;
            //    IRTestInfo iRTestInfo = new IRTestInfo();
            //    iRTestInfo.IRString = TestBoard_Left.ReadLine();
            //    iRTestInfo.Point = MotionPoint_Left;
            //    SP_infoList_Left.Add(iRTestInfo);
            //}
            //catch
            //{
            //    MessageBox.Show("测试板卡左获取消息异常");
            //}

        }

        private void TestBoard_Right_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            //try
            //{
            //    KeyDown_Right = false;
            //    IRTestInfo iRTestInfo = new IRTestInfo();
            //    iRTestInfo.IRString = TestBoard_Right.ReadLine();
            //    iRTestInfo.Point = MotionPoint_Right;
            //    SP_infoList_Right.Add(iRTestInfo);
            //}
            //catch
            //{
            //    MessageBox.Show("测试板卡右获取消息异常");
            //}
        }

        private void button8_Click(object sender, EventArgs e)
        {
            switch (comboBox2.SelectedIndex)
            {
                case 0:
                    if (GetImage_task_Right == null)
                    {
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera5, pictureBox19));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Right);
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera5, pictureBox19));

                    }
                    break;
                case 1:
                    if (GetImage_task_Right == null)
                    {
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera6, pictureBox19));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Right);
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera6, pictureBox19));

                    }
                    break;
                case 2:
                    if (GetImage_task_Right == null)
                    {
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera7, pictureBox19));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Right);
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera7, pictureBox19));

                    }
                    break;
                case 3:
                    if (GetImage_task_Right == null)
                    {
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera8, pictureBox19));
                    }
                    else
                    {
                        continuousImage = false;

                        Task.WaitAll(GetImage_task_Right);
                        continuousImage = true;
                        GetImage_task_Right = Task.Run(() => CameraContinousImage(Camera8, pictureBox19));

                    }
                    break;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.RemoveAt(listView1.SelectedItems[0].Index);
            listView1.Items.RemoveAt(listView1.SelectedItems[0].Index);
        }

        private void listView1_DockChanged(object sender, EventArgs e)
        {
            MessageBox.Show(listView1.SelectedItems[0].ToString());
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (comboBox11.Text != "")
            {
                MotionPoint motionPoint = new MotionPoint();
                motionPoint.X = axisParameter.Axis1Mpos;
                motionPoint.Y = axisParameter.Axis2Mpos;
                motionPoint.Down_Z = axisParameter.Axis5Mpos;
                int index = listView1.SelectedItems[0].Index;
                Form2 form2 = new Form2(configFile.MotionControl_List[comboBox11.Text].motioncontrol_Left.motionPoints[index], Code_Station_Left);
                form2.NowPoint = motionPoint;
                form2.ShowDialog();
                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Text = form2.point.Name;
                switch (form2.point.pointStyle)
                {
                    case PointStyle.IOContrlo:
                        listViewItem.SubItems.Add("IO控制");
                        break;
                    case PointStyle.KeyTest:
                        listViewItem.SubItems.Add("按键测试");
                        break;
                    case PointStyle.Camera:
                        listViewItem.SubItems.Add("相机拍照");
                        break;
                    case PointStyle.KeyTest_IO:
                        listViewItem.SubItems.Add("按键测试&气缸动作");
                        break;
                    case PointStyle.Move:
                        listViewItem.SubItems.Add("移动");
                        break;
                    case PointStyle.Wait:
                        listViewItem.SubItems.Add("等待");
                        break;

                }

                listViewItem.SubItems.Add(form2.point.Code_Value);
                listViewItem.SubItems.Add(form2.point.X.ToString());
                listViewItem.SubItems.Add(form2.point.Y.ToString());
                listViewItem.SubItems.Add(form2.point.Up_Z.ToString());
                listViewItem.SubItems.Add(form2.point.Down_Z.ToString());
                listView1.Items[index] = listViewItem;
                configFile.MotionControl_List[comboBox11.Text].motioncontrol_Left.motionPoints[index] = form2.point;
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
                int Index_listView = listView1.SelectedItems[0].Index;
                ListViewItem listViewItem = listView1.Items[Index_listView];
                MotionPoint motionPoint = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[Index_listView];
                if (Index_listView > 0)
                {
                    listView1.Items.RemoveAt(Index_listView);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.RemoveAt(Index_listView);
                    listView1.Items.Insert(Index_listView - 1, listViewItem);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Insert(Index_listView - 1, motionPoint);
                }
            }

        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
                int Index_listView = listView1.SelectedItems[0].Index;
                ListViewItem listViewItem = listView1.Items[Index_listView];
                MotionPoint motionPoint = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[Index_listView];
                if (Index_listView < listView1.Items.Count - 1)
                {
                    listView1.Items.RemoveAt(Index_listView);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.RemoveAt(Index_listView);
                    listView1.Items.Insert(Index_listView + 1, listViewItem);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Insert(Index_listView + 1, motionPoint);
                }
            }
        }

        private void pictureBox15_Click(object sender, EventArgs e)
        {

            MotionPoint motionPoint = new MotionPoint();
            motionPoint.X = axisParameter.Axis3Mpos;
            motionPoint.Y = axisParameter.Axis4Mpos;
            motionPoint.Down_Z = axisParameter.Axis6Mpos;
            Form2 form2 = new Form2(motionPoint, Code_Station_Right);
            form2.ShowDialog();
            ListViewItem listViewItem = new ListViewItem();
            listViewItem.Text = form2.point.Name;

            switch (form2.point.pointStyle)
            {
                case PointStyle.IOContrlo:
                    listViewItem.SubItems.Add("IO控制");
                    break;
                case PointStyle.KeyTest:
                    listViewItem.SubItems.Add("按键测试");
                    break;
                case PointStyle.Camera:
                    listViewItem.SubItems.Add("相机拍照");
                    break;
                case PointStyle.KeyTest_IO:
                    listViewItem.SubItems.Add("按键测试&气缸动作");
                    break;
                case PointStyle.Move:
                    listViewItem.SubItems.Add("移动");
                    break;
                case PointStyle.Wait:
                    listViewItem.SubItems.Add("等待");
                    break;

            }

            listViewItem.SubItems.Add(form2.point.Code_Value);
            listViewItem.SubItems.Add(form2.point.X.ToString());
            listViewItem.SubItems.Add(form2.point.Y.ToString());
            listViewItem.SubItems.Add(form2.point.Up_Z.ToString());
            listViewItem.SubItems.Add(form2.point.Down_Z.ToString());
            listView2.Items.Add(listViewItem);
            configFile.productList[NowProductID].motioncontrol_Right.motionPoints.Add(form2.point);
        }

        private void button18_Click(object sender, EventArgs e)
        {
            configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.RemoveAt(listView2.SelectedItems[0].Index);
            listView2.Items.RemoveAt(listView2.SelectedItems[0].Index);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
                int Index_listView = listView2.SelectedItems[0].Index;
                ListViewItem listViewItem = listView2.Items[Index_listView];
                MotionPoint motionPoint = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[Index_listView];
                if (Index_listView > 0)
                {
                    listView2.Items.RemoveAt(Index_listView);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.RemoveAt(Index_listView);
                    listView2.Items.Insert(Index_listView - 1, listViewItem);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Insert(Index_listView - 1, motionPoint);
                }
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
                int Index_listView = listView2.SelectedItems[0].Index;
                ListViewItem listViewItem = listView2.Items[Index_listView];
                MotionPoint motionPoint = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[Index_listView];
                if (Index_listView < listView2.Items.Count - 1)
                {
                    listView2.Items.RemoveAt(Index_listView);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.RemoveAt(Index_listView);
                    listView2.Items.Insert(Index_listView + 1, listViewItem);
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Insert(Index_listView + 1, motionPoint);
                }
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {

            HObject Image_H, RotateImage;
            HTuple w, h;
            switch (comboBox3.SelectedIndex)
            {
                case 0:
                    ManualGetImage = Camera1.GetImageBitMap();
                    break;
                case 1:
                    ManualGetImage = Camera2.GetImageBitMap();
                    break;
                case 2:
                    ManualGetImage = Camera3.GetImageBitMap();
                    break;
                case 3:
                    ManualGetImage = Camera4.GetImageBitMap();
                    break;
                case 4:
                    ManualGetImage = Camera5.GetImageBitMap();
                    break;
                case 5:
                    ManualGetImage = Camera6.GetImageBitMap();
                    break;
                case 6:
                    ManualGetImage = Camera7.GetImageBitMap();
                    break;
                case 7:
                    ManualGetImage = Camera8.GetImageBitMap();
                    break;
                default:
                    ManualGetImage = Camera1.GetImageBitMap();
                    break;
            }
            ImageConvert.Bitmap2HObjectS(ManualGetImage, out Image_H);
            HOperatorSet.RotateImage(Image_H, out RotateImage, 90, "constant");
            HOperatorSet.GetImageSize(RotateImage, out w, out h);
            HOperatorSet.SetPart(hSmartWindowControl9.HalconWindow, 0, 0, h - 1, w - 1);
            HOperatorSet.DispObj(RotateImage, hSmartWindowControl9.HalconWindow);
            ModelImage = RotateImage;



        }

        private void button20_Click(object sender, EventArgs e)
        {

            if (comboBox11.Text != "")
            {
                DialogResult dialogResult = MessageBox.Show("是否清空点位", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.OK)
                {
                    listView1.Items.Clear();
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Clear();
                }
                else
                {
                    return;
                }
            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                CFloatValue Camera_ExposureTime = new CFloatValue();
                switch (comboBox3.SelectedIndex)
                {
                    case 0:
                        Camera1.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 1:
                        Camera2.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 2:
                        Camera3.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 3:
                        Camera4.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 4:
                        Camera5.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 5:
                        Camera6.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 6:
                        Camera7.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                    case 7:
                        Camera8.m_MyCamera.GetFloatValue("ExposureTime", ref Camera_ExposureTime);
                        textBox25.Text = Camera_ExposureTime.CurValue.ToString();
                        break;
                }
            }
            catch
            {

            }
        }

        private void button22_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(@"D:\SaveImage") == false)
            {
                Directory.CreateDirectory(@"D:\SaveImage");
            }
            if (ManualGetImage != null)
            {
                ManualGetImage.Save(@"D:\SaveImage\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }

        private void button23_Click(object sender, EventArgs e)
        {
            if (DraROI != null) DraROI.ClearDrawingObject();
            switch (comboBox4.SelectedIndex)
            {
                case 0:
                    DraROI = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE1, 100, 100, 200, 200);
                    break;
                case 1:
                    DraROI = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE2, 300, 200, 0, 100, 20);
                    break;
                case 2:
                    DraROI = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.CIRCLE, 100, 100, 50);
                    break;
                case 3:
                    DraROI = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, 100, 100, 100, 200);
                    break;
                default:
                    DraROI = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE1, 100, 100, 200, 200);
                    break;

            }
            DraROI.SetDrawingObjectParams("color", "green");
            hSmartWindowControl9.HalconWindow.AttachDrawingObjectToWindow(DraROI);

        }

        private void button24_Click(object sender, EventArgs e)
        {
            try
            {
                DraROI.ClearDrawingObject();
            }
            catch
            {

            }
        }

        private void button21_Click(object sender, EventArgs e)
        {
            if (comboBox7.SelectedIndex > -1)
            {
                HTuple ang = new HTuple();
                HTuple hTuple = new HTuple(); 
                 HTuple w, h;
                HObject ROI = new HObject();

                if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel) == false)
                {
                    Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel);
                }
                try
                {
                    if (radioButton3.Checked == true)
                    {
                        algorithm.GetScreen(ModelImage, out Manual_YJImage, out Manual_YJImage_Em, out ang);
                    }

                    if (radioButton4.Checked == true)
                    {
                        HOperatorSet.ReadShapeModel(Directory.GetCurrentDirectory() + @"\Model\Black_FindModel", out HTuple ScreenFindModel);
                        algorithm.Get_Screen_Black(ModelImage, out Manual_YJImage, out Manual_YJImage_Em, ScreenFindModel, out ang);
                    }
                    ModelImage = Manual_YJImage_Em;
                    hSmartWindowControl9.HalconWindow.ClearWindow();
                    HOperatorSet.GetImageSize(Manual_YJImage_Em, out w, out h);
                    HOperatorSet.SetPart(hSmartWindowControl9.HalconWindow, 0, 0, h - 1, w - 1);
                    HOperatorSet.DispObj(Manual_YJImage_Em, hSmartWindowControl9.HalconWindow);
                }
                catch
                {
                    MessageBox.Show("获取液晶屏幕异常");
                }

            }
            else
            {
                MessageBox.Show("请选择需要编辑的模型");
            }
        }

        private void button25_Click(object sender, EventArgs e)
        {
            HObject Image_H, RotateImage;
            HTuple w, h;
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Title = "导入一张图片";
            openFileDialog.Filter = "图片文件(*.jpg,*.gif,*.bmp,*.png)|*.jpg;*.gif;*.bmp;*.png";
            openFileDialog.ShowDialog();

            if (openFileDialog.FileName != "")
            {
                if (radioButton3.Checked == true)
                {
                    ManualGetImage = new Bitmap(openFileDialog.FileName);
                    ImageConvert.Bitmap2HObjectS(ManualGetImage, out Image_H);
                    HOperatorSet.RotateImage(Image_H, out RotateImage, 90, "constant");
                    HOperatorSet.GetImageSize(RotateImage, out w, out h);
                    HOperatorSet.SetPart(hSmartWindowControl9.HalconWindow, 0, 0, h - 1, w - 1);
                    HOperatorSet.DispObj(RotateImage, hSmartWindowControl9.HalconWindow);
                    ModelImage = RotateImage;
                }

                if (radioButton4.Checked == true)
                {
                    ManualGetImage = new Bitmap(openFileDialog.FileName);
                    ImageConvert.Bitmap2HObjectS(ManualGetImage, out Image_H);
                    HOperatorSet.RotateImage(Image_H, out RotateImage, 90, "constant");
                    HOperatorSet.Rgb3ToGray(RotateImage, RotateImage, RotateImage, out RotateImage);
                    HOperatorSet.GetImageSize(RotateImage, out w, out h);
                    //HOperatorSet.InvertImage(RotateImage, out RotateImage);
                    HOperatorSet.SetPart(hSmartWindowControl9.HalconWindow, 0, 0, h - 1, w - 1);
                    HOperatorSet.DispObj(RotateImage, hSmartWindowControl9.HalconWindow);
                    ModelImage = RotateImage;
                }
            }
        }

        private void button26_Click(object sender, EventArgs e)
        {
            if (comboBox7.SelectedIndex > -1)
            {
                if (DraROI != null)
                {
                    if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ROI") == false)
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ROI");
                    }

                    if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\Region") == false)
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\Region");
                    }

                    if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ModelID") == false)
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ModelID");
                    }


                    HTuple ang = new HTuple(1.6).TupleRad() * -1;
                    string[] str;
                    HObject SelectRegion = new HObject();
                    HTuple hTuple = new HTuple();
                    HObject Image = new HObject();
                    HObject ROI = new HObject();
                    ExamineFeatrue featrue = new ExamineFeatrue();
                    if (DraROI != null)
                    {
                        switch (comboBox4.SelectedIndex)
                        {
                            case 0:
                                str = new string[] { "row1", "column1", "row2", "column2" };
                                hTuple = DraROI.GetDrawingObjectParams(str);
                                HOperatorSet.GenRectangle1(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                                break;
                            case 1:
                                str = new string[] { "row", "column", "phi", "Length1", "Length2" };
                                hTuple = DraROI.GetDrawingObjectParams(str);
                                HOperatorSet.GenRectangle2(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3], hTuple.LArr[3]);
                                break;
                            case 2:
                                str = new string[] { "row", "column", "radius" };
                                hTuple = DraROI.GetDrawingObjectParams(str);
                                HOperatorSet.GenCircle(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2]);
                                break;
                            case 3:
                                str = new string[] { "beginRow", "beginCol", "endRow", "endCol" };
                                hTuple = DraROI.GetDrawingObjectParams(str);
                                HOperatorSet.GenRegionLine(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                                break;
                            default:
                                str = new string[] { "row1", "column1", "row2", "column2" };
                                hTuple = DraROI.GetDrawingObjectParams(str);
                                HOperatorSet.GenRectangle1(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                                break;
                        }
                    }

                    if (Manual_YJImage_Em != null && textBox77.Text != "")
                    {
                        try
                        {

                            string ROI_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ROI\" + (listBox2.Items.Count + 1) + ".hobj";
                            string Region_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\Region\" + (listBox2.Items.Count + 1) + ".hobj";
                            string ModelID = Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ModelID\" + (listBox2.Items.Count + 1) + ".hobj";
                            algorithm.CreateModel_Key(Manual_YJImage_Em, ROI, out SelectRegion, Region_Path, ModelID, ROI_Path);
                            HOperatorSet.DispObj(SelectRegion, hSmartWindowControl9.HalconWindow);
                            listBox2.Items.Add("特征：" + (listBox2.Items.Count + 1));
                            InitExamineFeature();
                        }
                        catch
                        {
                            MessageBox.Show("请设置正确的分割阈值");
                        }
                    }
                    else
                    {
                        MessageBox.Show("图片为空");
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择需要编辑的模型");
            }
        }

        private void button31_Click(object sender, EventArgs e)
        {
            Clean_Dir(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ROI");
            Clean_Dir(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\Region");
            Clean_Dir(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ModelID");
            if (DraROI != null) DraROI.ClearDrawingObject();
            hSmartWindowControl9.HalconWindow.ClearWindow();
            ykqFeature.ScreenFeatures.Clear();
            configFile.productList[NowProductID].Config.ScreenGrayvalList.Clear();
            listBox2.Items.Clear();
        }

        private void button30_Click(object sender, EventArgs e)
        {
        }

        private void button32_Click(object sender, EventArgs e)
        {

            bool IsEmpty = false;
            if (ManualGetImage != null)
            {

                Console.WriteLine("测试结果:" + ScreenTest(hSmartWindowControl9, ManualGetImage, 10, listBox6, out IsEmpty));

            }

        }

        private void button41_Click(object sender, EventArgs e)
        {

        }

        private void button27_Click(object sender, EventArgs e)
        {
            Form3 form3 = new Form3();

            List<string> MotionControl_List = new List<string>();
            List<string> Screen_Model_List = new List<string>();
            List<string> Key_Model_list = new List<string>();

            foreach(KeyValuePair<string, MotionControl_Info>i in configFile.MotionControl_List)
            {
                MotionControl_List.Add(i.Key);
            }

            form3.Motion_List = MotionControl_List;
            form3.Screen_List = configFile.Screen_Model_List;
            form3.Key_List = configFile.Key_Model_List;

            form3.ShowDialog();
            if (form3.ModelName != "" && form3.ModelName != null)
            {
                Product product = new Product();
                product = (Product)configFile.productList[NowProductID].Clone();
                listBox1.Items.Add(form3.ModelName);
                product.Model = form3.ModelName;
                product.P_Style = form3.Product_Style;
                configFile.productList.Add(product);

                SaveConfig();
                NowProductID = FindProductID(configFile.CurrentMode, configFile);

            }
            else
            {
                MessageBox.Show("请输入正确的产品型号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int ProductID = FindProductID(listBox1.SelectedItem.ToString(), configFile);
 
   
            label131.Text = configFile.productList[ProductID].MotionControl_Name;
            label131.BackColor = Color.White;

    

        

            label133.Text = configFile.productList[ProductID].Screen_Model;
            label133.BackColor = Color.White;
                
            


     
            label233.Text = configFile.productList[ProductID].Key_Model;
            label233.BackColor = Color.White;
                
   
        }

        private void button28_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count == 0)
            {
                MessageBox.Show("请选择要删除的型号");
            }
            else
            {

                configFile.productList.RemoveAt(listBox1.SelectedIndex);
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
                SaveConfig();
                NowProductID = FindProductID(configFile.CurrentMode, configFile);

            }



        }

        private void button42_Click(object sender, EventArgs e)
        {

        }

        private void button40_Click(object sender, EventArgs e)
        {
            HTuple ang = new HTuple(1.6).TupleRad() * -1;
            string[] str;
            HTuple hTuple = new HTuple();
            HTuple w, h;
            HObject ROI = new HObject();
            HTuple ModelID = new HTuple();

            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString()) == false)
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString());
            }
            if (DraROI != null)
            {
                try
                {
                    switch (comboBox5.SelectedIndex)
                    {
                        case 0:
                            str = new string[] { "row1", "column1", "row2", "column2" };
                            hTuple = DraROI.GetDrawingObjectParams(str);
                            HOperatorSet.GenRectangle1(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                            break;
                        case 1:
                            str = new string[] { "row", "column", "phi", "Length1", "Length2" };
                            hTuple = DraROI.GetDrawingObjectParams(str);
                            HOperatorSet.GenRectangle2(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3], hTuple.LArr[3]);
                            break;
                        case 2:
                            str = new string[] { "row", "column", "radius" };
                            hTuple = DraROI.GetDrawingObjectParams(str);
                            HOperatorSet.GenCircle(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2]);
                            break;
                        case 3:
                            str = new string[] { "beginRow", "beginCol", "endRow", "endCol" };
                            hTuple = DraROI.GetDrawingObjectParams(str);
                            HOperatorSet.GenRegionLine(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                            break;
                    }



                    if (radioButton3.Checked == true)
                    {
                        string ModelPath = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\KeyLocationModel";
                        algorithm.Key_Create_Part_Model(ModelImage, ROI, ModelPath, out HTuple Key_ModelID);
                        algorithm.Get_KeyPart(ModelImage, out KeyImage, Key_ModelID, 500, 1400, out HTuple Length);
                        hSmartWindowControl9.HalconWindow.ClearWindow();
                        HOperatorSet.GetImageSize(KeyImage, out w, out h);
                        HOperatorSet.SetPart(hSmartWindowControl9.HalconWindow, 0, 0, h - 1, w - 1);
                        HOperatorSet.DispObj(KeyImage, hSmartWindowControl9.HalconWindow);
                        DraROI.ClearDrawingObject();
                        ModelImage = KeyImage;
                    }
                    if (radioButton4.Checked == true)
                    {
                        string ModelPath = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\KeyLocationModel";
                        algorithm.Key_Create_ImagePart_Black(ModelImage, ROI, out KeyImage, ModelPath, out ModelID);
                        HOperatorSet.InvertImage(KeyImage, out KeyImage);
                        hSmartWindowControl9.HalconWindow.ClearWindow();
                        HOperatorSet.GetImageSize(KeyImage, out w, out h);
                        HOperatorSet.SetPart(hSmartWindowControl9.HalconWindow, 0, 0, h - 1, w - 1);
                        HOperatorSet.DispObj(KeyImage, hSmartWindowControl9.HalconWindow);
                        DraROI.ClearDrawingObject();
                        ModelImage = KeyImage;
                    }

                }
                catch
                {
                    MessageBox.Show("获取按键异常");
                }
            }
        }

        private void button36_Click(object sender, EventArgs e)
        {


            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\ROI_Key") == false)
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\ROI_Key");
            }

            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\Region_Key") == false)
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\Region_Key");
            }

            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\ModelID_Key") == false)
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\ModelID_Key");
            }

            HTuple ang = new HTuple(0).TupleRad() * -1;
            string[] str;
            HTuple hTuple = new HTuple();
            HObject Image = new HObject();
            HObject ROI = new HObject();
            HObject SelectRegion = new HObject();
            ExamineFeatrue featrue = new ExamineFeatrue();
            if (DraROI != null)
            {
                switch (comboBox5.SelectedIndex)
                {   
                    case 0:
                        str = new string[] { "row1", "column1", "row2", "column2" };
                        hTuple = DraROI.GetDrawingObjectParams(str);
                        HOperatorSet.GenRectangle1(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                        break;
                    case 1:
                        str = new string[] { "row", "column", "phi", "Length1", "Length2" };
                        hTuple = DraROI.GetDrawingObjectParams(str);
                        HOperatorSet.GenRectangle2(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3], hTuple.LArr[3]);
                        break;
                    case 2:
                        str = new string[] { "row", "column", "radius" };
                        hTuple = DraROI.GetDrawingObjectParams(str);
                        HOperatorSet.GenCircle(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2]);
                        break;
                    case 3:
                        str = new string[] { "beginRow", "beginCol", "endRow", "endCol" };
                        hTuple = DraROI.GetDrawingObjectParams(str);
                        HOperatorSet.GenRegionLine(out ROI, hTuple.LArr[0], hTuple.LArr[1], hTuple.LArr[2], hTuple.LArr[3]);
                        break;
                }
            }
            if (KeyImage != null)
            {
                string ROI_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\ROI_Key\" + (listBox3.Items.Count + 1) + ".hobj";
                string Region_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\Region_Key\" + (listBox3.Items.Count + 1) + ".hobj";
                string ModelID = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\ModelID_Key\" + (listBox3.Items.Count + 1) + ".hobj";
                HObject ModelImage = new HObject();

                algorithm.CreateModel_Key(KeyImage, ROI, out SelectRegion, Region_Path, ModelID, ROI_Path);
                HOperatorSet.DispObj(SelectRegion, hSmartWindowControl9.HalconWindow);
                listBox3.Items.Add("特征：" + (listBox3.Items.Count + 1));
                InitExamineFeature();

            }

        }

        private void button35_Click(object sender, EventArgs e)
        {
            HObject ROI = new HObject();
            HObject Region_H = new HObject();
            HTuple ModelID = new HTuple();
            HObject Result_Region = new HObject();
            HTuple NG_Result = new HTuple();
            HTuple Count_obj = new HTuple();
            HObject SelectedRegions = new HObject();
            HObject testImage = new HObject();

            string[] ModelID_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\ModelID_Key");
            string[] ROI_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\ROI_Key");
            string[] Region_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + comboBox6.SelectedItem.ToString() + @"\Region_Key");
            if (configFile.productList[NowProductID].P_Style == Product.Product_Style.RomoteControl_black)
            {
                HOperatorSet.InvertImage(KeyImage, out testImage);
            }
            else
            {
                testImage = KeyImage;
            }
            if (ModelID_List.Length > 0)
            {
                for (int i = 0; i < ModelID_List.Length; i++)
                {
                    HOperatorSet.ReadRegion(out ROI, ROI_List[i]);
                    HOperatorSet.ReadRegion(out Region_H, Region_List[i]);
                    HOperatorSet.ReadShapeModel(ModelID_List[i], out ModelID);

                    algorithm.Test_Key(testImage, ROI, Region_H, out Result_Region, ModelID, out NG_Result);
                    HOperatorSet.SelectShape(Result_Region, out SelectedRegions, "area", "and", 150, 999999);
                    HOperatorSet.DispObj(SelectedRegions, hSmartWindowControl9.HalconWindow);
                    HOperatorSet.DispRegion(SelectedRegions, hSmartWindowControl9.HalconWindow);
                    HOperatorSet.SetColor(hSmartWindowControl9.HalconWindow, "#ff000080");
                    algorithm.set_display_font(hSmartWindowControl9.HalconWindow, 40, "mono", "true", "false");
                    HOperatorSet.CountObj(SelectedRegions, out Count_obj);
                    if (Count_obj < 1 && NG_Result == 1)
                    {
                        algorithm.disp_message(hSmartWindowControl9.HalconWindow, "OK", "window", 0, 0, "green", "true");

                    }
                    else
                    {

                        algorithm.disp_message(hSmartWindowControl9.HalconWindow, "NG", "window", 0, 0, "red", "true");
                    }
                }

            }

            Region_H.Dispose();
            ROI.Dispose();
            Result_Region.Dispose();
            SelectedRegions.Dispose();
        }

        private void button33_Click(object sender, EventArgs e)
        {
            YKQ_Test test1 = new YKQ_Test();
            test1.configFile = configFile;
            test1.SavaImage = false;
            test1.ykqFeature = ykqFeature;
            test1.NowProductID = NowProductID;
            test1.SavaImage = SavaImage;
            test1.Key_AreaMin = configFile.productList[NowProductID].Key_AreaMin;
            test1.KeyTest(hSmartWindowControl9, ManualGetImage, out bool IsEmpty);
        }

        private void button7_Click(object sender, EventArgs e)
        {

        }

        private void button43_Click(object sender, EventArgs e)
        {
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 0, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 1, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 2, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 3, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 4, 0);
            zmcaux.ZAux_Direct_SetAxisEnable(Phandle, 5, 0);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Camera1.Close();
            Camera2.Close();
            Camera3.Close();
            Camera4.Close();
            Camera5.Close();
            Camera6.Close();
            Camera7.Close();
            Camera8.Close();
            Environment.Exit(0);
        }

        private void listView2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (comboBox11.Text != "")
            {
                MotionPoint motionPoint = new MotionPoint();
                motionPoint.X = axisParameter.Axis3Mpos;
                motionPoint.Y = axisParameter.Axis4Mpos;
                motionPoint.Down_Z = axisParameter.Axis6Mpos;
                int index = listView2.SelectedItems[0].Index;
                Form2 form2 = new Form2(configFile.MotionControl_List[comboBox11.Text].motioncontrol_Right.motionPoints[index], Code_Station_Right);
                form2.NowPoint = motionPoint;
                form2.ShowDialog();
                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Text = form2.point.Name;
                switch (form2.point.pointStyle)
                {
                    case PointStyle.IOContrlo:
                        listViewItem.SubItems.Add("IO控制");
                        break;
                    case PointStyle.KeyTest:
                        listViewItem.SubItems.Add("按键测试");
                        break;
                    case PointStyle.Camera:
                        listViewItem.SubItems.Add("相机拍照");
                        break;
                    case PointStyle.KeyTest_IO:
                        listViewItem.SubItems.Add("按键测试&气缸动作");
                        break;
                    case PointStyle.Move:
                        listViewItem.SubItems.Add("移动");
                        break;
                    case PointStyle.Wait:
                        listViewItem.SubItems.Add("等待");
                        break;

                }

                listViewItem.SubItems.Add(form2.point.Code_Value);
                listViewItem.SubItems.Add(form2.point.X.ToString());
                listViewItem.SubItems.Add(form2.point.Y.ToString());
                listViewItem.SubItems.Add(form2.point.Up_Z.ToString());
                listViewItem.SubItems.Add(form2.point.Down_Z.ToString());
                listView2.Items[index] = listViewItem;
                configFile.MotionControl_List[comboBox11.Text].motioncontrol_Right.motionPoints[index] = form2.point;
            }
        }

        private void button44_Click(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
              configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].AxisList = new int[] { 0, 1, 4 };
              configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Phandle = Phandle;
              configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].execute("Left");
            }
        }
        private void button45_Click(object sender, EventArgs e)
        {
            TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Switch_Current:1");
            Thread.Sleep(1000);
            TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Static_Current");
            Thread.Sleep(1000);
            TestBoard_Left.SendMsg(configFile.TestBoard_Left_PortName, "Switch_Current:0");
            Thread.Sleep(1000);
        }
        private void button46_Click(object sender, EventArgs e)
        {
            TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Switch_Current:1");
            Thread.Sleep(1000);
            TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Static_Current");
            Thread.Sleep(1000);
            TestBoard_Right.SendMsg(configFile.TestBoard_Right_PortName, "Switch_Current:0");

        }

        private void button15_Click(object sender, EventArgs e)
        {
            autoRunMode = true;
            Station_RunLeftNet = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            autoRunMode = true;
            Station_RunRightNet = true;
        }

        private void button7_Click_1(object sender, EventArgs e)
        {
            if (comboBox11.Text != "")
            {
                DialogResult dialogResult = MessageBox.Show("是否确定情况左右位运动轨迹", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.OK)
                {
                    listView2.Items.Clear();
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Clear();
                }
                else
                {
                    MessageBox.Show("密码错误");
                }
            }
        }


        private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl2.SelectedIndex == 2)
            {
                autoRunMode = false;
            }
        }
        private void tabPage9_Click(object sender, EventArgs e)
        {

        }
        private void button29_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count == 0)
            {
                MessageBox.Show("请选择型号");
            }
            else
            {

                if (listBox1.SelectedIndex > -1)
                {
                    NowProductID = FindProductID(listBox1.SelectedItem.ToString(), configFile);
                    configFile.CurrentMode = listBox1.SelectedItem.ToString();
                    InitExamineFeature();
                    label61.Text = configFile.productList[NowProductID].Model;
                    Refresh_Motion_Left();
                    Refresh_Motion_Right();
                }

                //读取新的产品参数

                //切换视觉检测特征
                listBox2.Items.Clear();
                listBox3.Items.Clear();

                textBox77.Text = configFile.productList[NowProductID].GetScreen_Scaled_Value1.ToString();
                textBox93.Text = configFile.productList[NowProductID].GetScreen_Scaled_Value2.ToString();
                textBox100.Text = configFile.productList[NowProductID].Screen_AreaMin.ToString();
                algorithm.Scaled_Value1 = configFile.productList[NowProductID].GetScreen_Scaled_Value1;
                algorithm.Scaled_Value2 = configFile.productList[NowProductID].GetScreen_Scaled_Value2;
                algorithm.Screen_AreaMin = configFile.productList[NowProductID].Screen_AreaMin;
                if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\" + configFile.productList[NowProductID].Model) == true)
                {
                    try
                    {
                        string[] ScreenFearure = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\ModelID");
                        if (ScreenFearure.Length > 0)
                        {
                            for (int i = 0; i < ScreenFearure.Length; i++)
                            {
                                listBox2.Items.Add("特征:" + (i + 1));
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("遍历液晶模板文件异常");
                    }



                    try
                    {
                        string[] ScreenFearure = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Key_Model + @"\ModelID_Key");
                        if (ScreenFearure.Length > 0)
                        {
                            for (int i = 0; i < ScreenFearure.Length; i++)
                            {
                                listBox3.Items.Add("特征:" + (i + 1));
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("遍历按键模板文件异常");
                    }
                }
            }

            //更新检测参数的显示
            textBox40.Text = configFile.productList[NowProductID].Config.QuiescentCurrentMax.ToString();
            textBox42.Text = configFile.productList[NowProductID].Config.QuiescentCurrentMin.ToString();

            textBox41.Text = configFile.productList[NowProductID].Config.DynamiccurrentMax.ToString();
            textBox43.Text = configFile.productList[NowProductID].Config.DynamiccurrentMin.ToString();

            textBox44.Text = configFile.productList[NowProductID].Config.CarrierFrequencyMax.ToString();

            textBox45.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel1.ToString();
            textBox46.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel2.ToString();
            textBox47.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel3.ToString();
            textBox48.Text = configFile.productList[NowProductID].Config.RadiancyLeft_Channel4.ToString();
            textBox49.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel1.ToString();
            textBox50.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel2.ToString();
            textBox51.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel3.ToString();
            textBox52.Text = configFile.productList[NowProductID].Config.RadiancyRight_Channel4.ToString();
            textBox57.Text = configFile.productList[NowProductID].Config.CarrierFrequencyMin.ToString();
            textBox72.Text = configFile.productList[NowProductID].IR_Count.ToString();

            // 切换相机曝光程序

            try
            {
                Camera1.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera1ExposureTime);
                Camera2.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera2ExposureTime);
                Camera3.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera3ExposureTime);
                Camera4.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera4ExposureTime);
                Camera5.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera5ExposureTime);
                Camera6.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera6ExposureTime);
                Camera7.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera7ExposureTime);
                Camera8.m_MyCamera.SetFloatValue("ExposureTime", configFile.productList[NowProductID].Config.Camera8ExposureTime);
            }
            catch
            {
                Camera1.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera2.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera3.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera4.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera5.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera6.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera7.m_MyCamera.SetFloatValue("ExposureTime", 5000);
                Camera8.m_MyCamera.SetFloatValue("ExposureTime", 5000);
            }

            if (File.Exists(Directory.GetCurrentDirectory() + @"\Model\" + configFile.productList[NowProductID].Model + ".onnx") == true)
            {
                inference_Onnx = new Inference_onnx(Directory.GetCurrentDirectory() + @"\Model\" + configFile.productList[NowProductID].Model + ".onnx", Directory.GetCurrentDirectory() + @"\Model\Lable.txt");
                isNewInfercesMode = true;
            }
            else
            {
                if (File.Exists(Directory.GetCurrentDirectory() + @"\Model\best.onnx") == true && File.Exists(Directory.GetCurrentDirectory() + @"\Model\Lable.txt") == true)
                {
                    inference_Onnx = new Inference_onnx(Directory.GetCurrentDirectory() + @"\Model\best.onnx", Directory.GetCurrentDirectory() + @"\Model\Lable.txt");
                }
                else
                {
                    radioButton5.Checked = true;
                }
                isNewInfercesMode = false;
            }
            try
            {
                if (configFile.MotionControl_List[configFile.productList[NowProductID].MotionControl_Name].motioncontrol_Left.motionPoints.Count > 0)
                {
                    comboBox11.Text = configFile.productList[NowProductID].MotionControl_Name;
                }
            }
            catch (Exception)
            {
                comboBox11.Text = null;

            }
            DialogResult result = MessageBox.Show("产品已经切换" + listBox1.SelectedItem.ToString() + "是否需要偏移按键坐标", "提示", MessageBoxButtons.YesNoCancel);
            if (result == DialogResult.Yes)
            {
                tabControl1.SelectedTab = tabPage2;
            }
            if (result == DialogResult.No)
            {
                tabControl1.SelectedTab = tabPage1;
            }

        }

        private void button43_Click_1(object sender, EventArgs e)
        {
            SaveDataToTxtBox(textBox40, ref configFile.productList[NowProductID].Config.QuiescentCurrentMax);

            SaveDataToTxtBox(textBox42, ref configFile.productList[NowProductID].Config.QuiescentCurrentMin);

            SaveDataToTxtBox(textBox41, ref configFile.productList[NowProductID].Config.DynamiccurrentMax);
            SaveDataToTxtBox(textBox43, ref configFile.productList[NowProductID].Config.DynamiccurrentMin);

            SaveDataToTxtBox(textBox44, ref configFile.productList[NowProductID].Config.CarrierFrequencyMax);
            SaveDataToTxtBox(textBox57, ref configFile.productList[NowProductID].Config.CarrierFrequencyMin);
            SaveDataToTxtBox(textBox45, ref configFile.productList[NowProductID].Config.RadiancyLeft_Channel1);
            SaveDataToTxtBox(textBox46, ref configFile.productList[NowProductID].Config.RadiancyLeft_Channel2);
            SaveDataToTxtBox(textBox47, ref configFile.productList[NowProductID].Config.RadiancyLeft_Channel3);
            SaveDataToTxtBox(textBox48, ref configFile.productList[NowProductID].Config.RadiancyLeft_Channel4);
            SaveDataToTxtBox(textBox49, ref configFile.productList[NowProductID].Config.RadiancyRight_Channel1);
            SaveDataToTxtBox(textBox50, ref configFile.productList[NowProductID].Config.RadiancyRight_Channel2);
            SaveDataToTxtBox(textBox51, ref configFile.productList[NowProductID].Config.RadiancyRight_Channel3);
            SaveDataToTxtBox(textBox52, ref configFile.productList[NowProductID].Config.RadiancyRight_Channel4);
            SaveDataToTxtBox(textBox72, ref configFile.productList[NowProductID].IR_Count);
            MessageBox.Show("写入成功", "提示");
        }

        private void button34_Click(object sender, EventArgs e)
        {
            Clean_Dir(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\ROI_Key");
            Clean_Dir(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\Region_Key");
            Clean_Dir(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\ModelID_Key");
            try
            {
                if (DraROI != null) DraROI.ClearDrawingObject();
            }
            catch
            {

            }


            hSmartWindowControl9.HalconWindow.ClearWindow();
            ykqFeature.KeyFeatures.Clear();
            listBox3.Items.Clear();
        }

        private void button47_Click(object sender, EventArgs e)
        {
            IR_BOX1.Items.Clear();
            IR_BOX2.Items.Clear();
            IR_BOX3.Items.Clear();
            IR_BOX4.Items.Clear();
            IR_BOX5.Items.Clear();
            IR_BOX6.Items.Clear();
            IR_BOX7.Items.Clear();
            IR_BOX8.Items.Clear();

        }

        private void button48_Click(object sender, EventArgs e)
        {
            Camera1.Close();
            Camera2.Close();
            Camera3.Close();
            Camera4.Close();
            Camera5.Close();
            Camera6.Close();
            Camera7.Close();
            Camera8.Close();
        }

        private void button49_Click(object sender, EventArgs e)
        {
            if (listView2.SelectedItems[0].Index > -1)
            {
                if (comboBox11.Text != "")
                {
                    MotionPoint motionPoint = new MotionPoint();
                    motionPoint = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index];
                    ListViewItem listViewItem = new ListViewItem();
                    listViewItem.Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Name;
                    switch (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].pointStyle)
                    {
                        case PointStyle.IOContrlo:
                            listViewItem.SubItems.Add("IO控制");
                            break;
                        case PointStyle.KeyTest:
                            listViewItem.SubItems.Add("按键测试");
                            break;
                        case PointStyle.Camera:
                            listViewItem.SubItems.Add("相机拍照");
                            break;
                        case PointStyle.KeyTest_IO:
                            listViewItem.SubItems.Add("按键测试&气缸动作");
                            break;
                        case PointStyle.Move:
                            listViewItem.SubItems.Add("移动");
                            break;
                        case PointStyle.Wait:
                            listViewItem.SubItems.Add("等待");
                            break;

                    }
                    listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Code_Value);
                    listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].X.ToString());
                    listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Y.ToString());
                    listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Up_Z.ToString());
                    listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Down_Z.ToString());
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Add(motionPoint);
                    listView2.Items.Add(listViewItem);
                }
            }
            else
            {
                MessageBox.Show("请选中要复制的点位", "提示");
            }
        }

        private void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                IRCode_InputMode_Left = true;
                if (motioncontrol_Left.motionPoints.Count > 0)
                {
                    for (int i = 0; i < motioncontrol_Left.motionPoints.Count; i++)
                    {
                        motioncontrol_Left.motionPoints[i].Code_Value = "";
                    }
                }


            }
            else
            {
                IRCode_InputMode_Left = false;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true)
            {
                configFile.Shield_ScreenTest = true;
            }
            else
            {
                configFile.Shield_ScreenTest = false;
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true)
            {
                configFile.Shield_KeyTest = true;
            }
            else
            {
                configFile.Shield_KeyTest = false;
            }
        }

        private void checkBox4_CheckStateChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked == true)
            {
                IRCode_InputMode_Right = true;
                if (motioncontrol_Right.motionPoints.Count > 0)
                {
                    for (int i = 0; i < motioncontrol_Right.motionPoints.Count; i++)
                    {
                        motioncontrol_Right.motionPoints[i].Code_Value = "";
                    }
                }
            }
            else
            {
                IRCode_InputMode_Right = false;
            }
        }

        private void button50_Click(object sender, EventArgs e)
        {
            ProductTotal.TotalClear();
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = "0"; }), label103);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = "0"; }), label105);
            this.BeginInvoke((Action<Label>)(theLable => { theLable.Text = "0"; }), label107);
        }

        private void button51_Click(object sender, EventArgs e)
        {
            try
            {

                ykqFeature.KeyFeatures.Clear();
                ykqFeature.ScreenFeatures.Clear();
                string Json_Config = JsonConvert.SerializeObject(configFile);

                FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\Config.json", FileMode.Create, FileAccess.Write);
                StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.Default);
                streamWriter1.Write(Json_Config);
                streamWriter1.Close();
                fileStream1.Close();
                MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception error)
            {
                MessageBox.Show("保存失败 \n\r" + error.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button52_Click(object sender, EventArgs e)
        {
            try
            {
                string Json_Config = JsonConvert.SerializeObject(configFile);
                FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\Config.json", FileMode.Create, FileAccess.Write);
                StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.Default);
                streamWriter1.Write(Json_Config);
                streamWriter1.Close();
                fileStream1.Close();
                MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button53_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex > -1)
            {
                try
                {
                    string ROI_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ROI\" + (listBox2.SelectedIndex + 1) + ".hobj";
                    string Region_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\Region\" + (listBox2.SelectedIndex + 1) + ".hobj";
                    string ModelID = Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ModelID\" + (listBox2.SelectedIndex + 1) + ".hobj";
                    File.Delete(ROI_Path);
                    File.Delete(Region_Path);
                    File.Delete(ModelID);
                    listBox2.Items.RemoveAt(listBox2.SelectedIndex);
                    ykqFeature.ScreenFeatures.RemoveAt(listBox2.SelectedIndex);
                    //configFile.productList[NowProductID].Config.ScreenGrayvalList.RemoveAt(listBox2.SelectedIndex);
                    MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void button54_Click(object sender, EventArgs e)
        {
            if (listBox3.SelectedIndex > -1)
            {
                try
                {
                    string ROI_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Model + @"\ROI_Key\" + (listBox3.SelectedIndex + 1) + ".hobj";
                    string Region_Path = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Model + @"\Region_Key\" + (listBox3.SelectedIndex + 1) + ".hobj";
                    string ModelID = Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Model + @"\ModelID_Key\" + (listBox3.SelectedIndex + 1) + ".hobj";
                    File.Delete(ROI_Path);
                    File.Delete(Region_Path);
                    File.Delete(ModelID);
                    listBox3.Items.RemoveAt(listBox3.SelectedIndex);
                    ykqFeature.KeyFeatures.RemoveAt(listBox3.SelectedIndex);
                    MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void InitExamineFeature()
        {
            //更新特征列表
            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\ModelID") == true)
            {
                string[] ModelID_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\ModelID");
                string[] ROI_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\ROI");
                string[] Region_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + configFile.productList[NowProductID].Screen_Model + @"\Region");
                ykqFeature.ScreenFeatures.Clear();
                if (ModelID_List.Length > 0)
                {
                    for (int i = 0; i < ModelID_List.Length; i++)
                    {
                        ExamineFeatrue featrue = new ExamineFeatrue();
                        HOperatorSet.GenImageConst(out featrue.FeatureRegion, "byte", 10000, 10000);
                        HOperatorSet.GenImageConst(out featrue.FeatureROI, "byte", 10000, 10000);
                        ykqFeature.ScreenFeatures.Add(featrue);
                    }

                    for (int j = 0; j < ModelID_List.Length; j++)
                    {
                        HOperatorSet.ReadRegion(out ykqFeature.ScreenFeatures[j].FeatureROI, ROI_List[j]);
                        HOperatorSet.ReadRegion(out ykqFeature.ScreenFeatures[j].FeatureRegion, Region_List[j]);
                        HOperatorSet.ReadShapeModel(ModelID_List[j], out ykqFeature.ScreenFeatures[j].Model);
                    }
                }
            }

            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Key_Model + @"\ModelID_Key") == true)
            {

                string[] ModelID_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Key_Model + @"\ModelID_Key");
                string[] ROI_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Key_Model + @"\ROI_Key");
                string[] Region_List = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + configFile.productList[NowProductID].Key_Model + @"\Region_Key");
                ykqFeature.KeyFeatures.Clear();
                if (ModelID_List.Length > 0)
                {
                    for (int i = 0; i < ModelID_List.Length; i++)
                    {
                        ExamineFeatrue featrue = new ExamineFeatrue();
                        HOperatorSet.GenImageConst(out featrue.FeatureRegion, "byte", 10000, 10000);
                        HOperatorSet.GenImageConst(out featrue.FeatureROI, "byte", 10000, 10000);
                        ykqFeature.KeyFeatures.Add(featrue);
                    }

                    for (int k = 0; k < ModelID_List.Length; k++)
                    {
                        HOperatorSet.ReadRegion(out ykqFeature.KeyFeatures[k].FeatureROI, ROI_List[k]);
                        HOperatorSet.ReadRegion(out ykqFeature.KeyFeatures[k].FeatureRegion, Region_List[k]);
                        HOperatorSet.ReadShapeModel(ModelID_List[k], out ykqFeature.KeyFeatures[k].Model);
                    }
                }
            }
        }

        private void button57_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex > -1)
            {
                HOperatorSet.DispRegion(ykqFeature.ScreenFeatures[listBox2.SelectedIndex].FeatureROI, hSmartWindowControl9.HalconWindow);
            }
        }

        private void button58_Click(object sender, EventArgs e)
        {
            if (listBox3.SelectedIndex > -1)
            {
                HOperatorSet.DispRegion(ykqFeature.KeyFeatures[listBox3.SelectedIndex].FeatureROI, hSmartWindowControl9.HalconWindow);
            }
            else
            {
                MessageBox.Show("无效");
            }

        }

        private void button59_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems[0].Index > -1)
            {
                MotionPoint motionPoint = new MotionPoint();
                motionPoint = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index];
                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Name;
                switch (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].pointStyle)
                {
                    case PointStyle.IOContrlo:
                        listViewItem.SubItems.Add("IO控制");
                        break;
                    case PointStyle.KeyTest:
                        listViewItem.SubItems.Add("按键测试");
                        break;
                    case PointStyle.Camera:
                        listViewItem.SubItems.Add("相机拍照");
                        break;
                    case PointStyle.KeyTest_IO:
                        listViewItem.SubItems.Add("按键测试&气缸动作");
                        break;
                    case PointStyle.Move:
                        listViewItem.SubItems.Add("移动");
                        break;
                    case PointStyle.Wait:
                        listViewItem.SubItems.Add("等待");
                        break;

                }
                listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Code_Value);
                listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].X.ToString());
                listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Y.ToString());
                listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Up_Z.ToString());
                listViewItem.SubItems.Add(configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Down_Z.ToString());
                configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Add(motionPoint);
                listView1.Items.Add(listViewItem);
            }
            else
            {
                MessageBox.Show("请选中要复制的点位", "提示");
            }
        }

        private void button60_Click(object sender, EventArgs e)
        {

            float Value = 0;
            if (textBox58.Text != "")
            {
                if (comboBox11.Text !="")
                {
                    try
                    {
                        Value = Convert.ToSingle(textBox58.Text);
                        if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count; i++)
                            {
                                if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Up_Z = Value;
                                    listView1.Items[i].SubItems[5].Text = Value.ToString();
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }

        private void button61_Click(object sender, EventArgs e)
        {
            float Value = 0;
            if (textBox59.Text != "")
            {
                if (comboBox11.Text != "")
                {
                    try
                    {
                        Value = Convert.ToSingle(textBox59.Text);
                        if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count; i++)
                            {
                                if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Up_Z = Value;
                                    listView2.Items[i].SubItems[5].Text = Value.ToString();
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button62_Click(object sender, EventArgs e)
        {
            int Value = 0;
            if (textBox60.Text != "")
            {
                if (comboBox11.Text!="")
                {
                    try
                    {
                        Value = Convert.ToInt16(textBox60.Text);
                        if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count; i++)
                            {
                                if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].DelayTime_Down = Value;
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button63_Click(object sender, EventArgs e)
        {
            int Value = 0;
            if (textBox61.Text != "")
            {
                if (comboBox11.Text != "")
                {
                    try
                    {
                        Value = Convert.ToInt16(textBox61.Text);
                        if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count; i++)
                            {
                                if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].DelayTime_Down = Value;
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button64_Click(object sender, EventArgs e)
        {
            int Value = 0;
            if (textBox62.Text != "")
            {
                if (comboBox11.Text !="")
                {
                    try
                    {
                        Value = Convert.ToInt16(textBox62.Text);
                        if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count; i++)
                            {
                                if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].DelayTime_Up = Value;
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button65_Click(object sender, EventArgs e)
        {
            int Value = 0;
            if (textBox63.Text != "")
            {
                if (comboBox11.Text != "")
                {
                    try
                    {
                        Value = Convert.ToInt16(textBox63.Text);
                        if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count; i++)
                            {
                                if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].DelayTime_Up = Value;
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void label99_Click(object sender, EventArgs e)
        {

        }

        private void label101_Click(object sender, EventArgs e)
        {

        }

        private void button66_Click(object sender, EventArgs e)
        {
            configFile.Camera1Seria = textBox64.Text.Trim();
            configFile.Camera2Seria = textBox65.Text.Trim();
            configFile.Camera3Seria = textBox66.Text.Trim();
            configFile.Camera4Seria = textBox67.Text.Trim();
            configFile.Camera5Seria = textBox68.Text.Trim();
            configFile.Camera6Seria = textBox69.Text.Trim();
            configFile.Camera7Seria = textBox70.Text.Trim();
            configFile.Camera8Seria = textBox71.Text.Trim();
            MessageBox.Show("相机参数应用成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                configFile.productList[NowProductID].P_Style = Product.Product_Style.RomoteControl_White;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked == true)
            {
                configFile.productList[NowProductID].P_Style = Product.Product_Style.RomoteControl_black;
            }
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }

        private void button67_Click(object sender, EventArgs e)
        {

        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton5.Checked == true) configFile.algorithmicMode = 0;
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton6.Checked == true) configFile.algorithmicMode = 1;

        }

        private void button67_Click_1(object sender, EventArgs e)
        {
            configFile.TestBoard_Left_PortName = textBox73.Text;
            configFile.TestBoard_Right_PortName = textBox74.Text;
            try
            {
                InitSerialPort();
            }
            catch
            {
                MessageBox.Show("端口设置失败", "提示");
            }
        }

        private void button68_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count == 0)
            {
                MessageBox.Show("请选择要删除的型号");
            }
            else
            {

                Form3 form3 = new Form3();
                form3.Text = "修改产品名称";
                form3.ShowDialog();
                if (listBox1.SelectedIndex > -1)
                {

                    if (form3.ProductName != "")
                    {
                        configFile.productList[listBox1.SelectedIndex].Model = form3.ModelName;
                        listBox1.Items[listBox1.SelectedIndex] = form3.ModelName;
                    }
                }
                else
                {
                    MessageBox.Show("删除失败");
                }
            }

        }

        private void toolStripStatusLabel2_Click(object sender, EventArgs e)
        {

        }

        private void label103_Click(object sender, EventArgs e)
        {

        }

        private void label107_Click(object sender, EventArgs e)
        {

        }






        private void button69_Click(object sender, EventArgs e)
        {
        }

        private void button70_Click(object sender, EventArgs e)
        {
            SaveDataToTxtBox(textBox76, ref configFile.PLC_address.StartLeft);
            SaveDataToTxtBox(textBox80, ref configFile.PLC_address.GetMateriel_Left);
            SaveDataToTxtBox(textBox82, ref configFile.PLC_address.TestComplete_Left);
            SaveDataToTxtBox(textBox84, ref configFile.PLC_address.TestReult1_Left);
            SaveDataToTxtBox(textBox86, ref configFile.PLC_address.TestReult2_Left);
            SaveDataToTxtBox(textBox88, ref configFile.PLC_address.TestReult3_Left);
            SaveDataToTxtBox(textBox90, ref configFile.PLC_address.TestReult4_Left);

            SaveDataToTxtBox(textBox79, ref configFile.PLC_address.StartRight);
            SaveDataToTxtBox(textBox81, ref configFile.PLC_address.GetMateriel_Right);
            SaveDataToTxtBox(textBox83, ref configFile.PLC_address.TestComplete_Right);
            SaveDataToTxtBox(textBox85, ref configFile.PLC_address.TestReult1_Right);
            SaveDataToTxtBox(textBox87, ref configFile.PLC_address.TestReult2_Right);
            SaveDataToTxtBox(textBox89, ref configFile.PLC_address.TestReult3_Right);
            SaveDataToTxtBox(textBox91, ref configFile.PLC_address.TestReult4_Right);

            SaveDataToTxtBox(textBox105, ref configFile.PLC_address.Left_StationIsEmpty);
            SaveDataToTxtBox(textBox106, ref configFile.PLC_address.Right_StationIsEmpty);

            SaveDataToTxtBox(textBox92, ref configFile.PLCIP);
            SaveConfig();
        }

        private void listView3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void panel43_Paint(object sender, PaintEventArgs e)
        {

        }



        private void listView9_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listView10_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox5.Checked == true)
            {
                SavaImage = true;
            }
            else
            {
                SavaImage = false;
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button73_Click(object sender, EventArgs e)
        {

        }

        private void button71_Click(object sender, EventArgs e)
        {
            KeyDisp(hSmartWindowControl10, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl11, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl12, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl13, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl14, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl15, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl16, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            KeyDisp(hSmartWindowControl17, Directory.GetCurrentDirectory() + @"\Keyimg\Default.bmp");
            HOperatorSet.SetColor(hSmartWindowControl10.HalconWindow, "green");
            HOperatorSet.GenCircle(out HObject region, 216.551, 245.949, 50);
            HOperatorSet.DispRegion(region, hSmartWindowControl10.HalconWindow);

            HOperatorSet.SetColor(hSmartWindowControl10.HalconWindow, "red");
            HOperatorSet.GenCircle(out HObject region1, 100, 300, 50);
            HOperatorSet.DispRegion(region1, hSmartWindowControl10.HalconWindow);
        }

        private void richTextBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox6.Checked == true)
            {
                configFile.PLC_Start = true;
            }
            else
            {
                configFile.PLC_Start = false;
            }
            SaveConfig();
        }

        private void OUTPUT4_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void panel21_Paint(object sender, PaintEventArgs e)
        {

        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {




        }

        private void button76_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.ShowDialog();
            if (form4.ModelName != "")
            {
                bool exist = false;
                if (configFile.Key_Model_List.Count > 0)
                {
                    for (int i = 0; i < configFile.Key_Model_List.Count; i++)
                    {
                        if (configFile.Key_Model_List[i] == form4.ModelName)
                        {
                            exist = true;
                            break;
                        }
                    }
                }

                if (exist == false)
                {
                    configFile.Key_Model_List.Add(form4.ModelName);
                    comboBox6.Items.Add(form4.ModelName);
                }
                else
                {
                    MessageBox.Show("该模型已经存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("新增模型异常", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }




        private void timer2_Tick(object sender, EventArgs e)
        {
            button15_Click(null, null);

        }


        private void button72_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox77.Text != "")
                {
                    algorithm.Scaled_Value1 = Convert.ToDouble(textBox77.Text);
                    configFile.productList[NowProductID].GetScreen_Scaled_Value1 = Convert.ToDouble(textBox77.Text);
                }

                if (textBox93.Text != "")
                {
                    algorithm.Scaled_Value2 = Convert.ToDouble(textBox93.Text);
                    configFile.productList[NowProductID].GetScreen_Scaled_Value2 = Convert.ToDouble(textBox93.Text);
                }
                if (textBox100.Text != "")
                {
                    algorithm.Screen_AreaMin = Convert.ToInt16(textBox100.Text);
                    configFile.productList[NowProductID].Screen_AreaMin = Convert.ToInt16(textBox100.Text);
                }
                MessageBox.Show("参数设置成功");
            }
            catch
            {
                MessageBox.Show("参数设置异常");
            }
        }

        private void button75_Click(object sender, EventArgs e)
        {
            string export_str = JsonConvert.SerializeObject(configFile.productList[NowProductID], Formatting.Indented);
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog.Title = "产品导出";
            saveFileDialog.Filter = "*.Json|Json文件";
            saveFileDialog.DefaultExt = ".Json";
            DialogResult dialogResult = saveFileDialog.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {
                FileStream fileStream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write);
                StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.Default);
                streamWriter.Write(export_str);
            }

        }

        private void button77_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否对左工位X轴位置进行偏移", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    float offset_value = 0;
                    offset_value = Convert.ToSingle(textBox94.Text);
                    if (configFile.productList.Count > 0)
                    {
                        for (int i = 0; i < configFile.productList.Count; i++)
                        {
                            for (int k = 0; k < configFile.productList[i].motioncontrol_Left.motionPoints.Count; k++)
                            {
                                if (configFile.productList[i].motioncontrol_Left.motionPoints[k].pointStyle != PointStyle.IOContrlo)
                                {
                                    configFile.productList[i].motioncontrol_Left.motionPoints[k].X = configFile.productList[i].motioncontrol_Left.motionPoints[k].X + offset_value;
                                }
                            }
                        }
                    }

                }
                catch
                {
                    MessageBox.Show("偏移值设置异常");
                }
            }
        }

        private void button79_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否对左工位Y轴位置进行偏移", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    float offset_value = 0;
                    offset_value = Convert.ToSingle(textBox96.Text);
                    if (configFile.productList.Count > 0)
                    {
                        for (int i = 0; i < configFile.productList.Count; i++)
                        {
                            for (int k = 0; k < configFile.productList[i].motioncontrol_Left.motionPoints.Count; k++)
                            {
                                if (configFile.productList[i].motioncontrol_Left.motionPoints[k].pointStyle != PointStyle.IOContrlo)
                                {
                                    configFile.productList[i].motioncontrol_Left.motionPoints[k].Y = configFile.productList[i].motioncontrol_Left.motionPoints[k].Y + offset_value;
                                }
                            }
                        }
                    }

                }
                catch
                {
                    MessageBox.Show("偏移值设置异常");
                }
            }
        }

        private void button78_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否对左工位Z轴位置进行偏移", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    float offset_value = 0;
                    offset_value = Convert.ToSingle(textBox95.Text);
                    if (configFile.productList.Count > 0)
                    {
                        for (int i = 0; i < configFile.productList.Count; i++)
                        {
                            for (int k = 0; k < configFile.productList[i].motioncontrol_Left.motionPoints.Count; k++)
                            {
                                if (configFile.productList[i].motioncontrol_Left.motionPoints[k].pointStyle != PointStyle.IOContrlo)
                                {
                                    configFile.productList[i].motioncontrol_Left.motionPoints[k].Down_Z = configFile.productList[i].motioncontrol_Left.motionPoints[k].Down_Z + offset_value;
                                    configFile.productList[i].motioncontrol_Left.motionPoints[k].Up_Z = configFile.productList[i].motioncontrol_Left.motionPoints[k].Up_Z + offset_value;
                                }
                            }
                        }
                    }

                }
                catch
                {
                    MessageBox.Show("偏移值设置异常");
                }
            }
        }

        private void button80_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否对右工位X轴位置进行偏移", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    float offset_value = 0;
                    offset_value = Convert.ToSingle(textBox97.Text);
                    if (configFile.productList.Count > 0)
                    {
                        for (int i = 0; i < configFile.productList.Count; i++)
                        {
                            for (int k = 0; k < configFile.productList[i].motioncontrol_Right.motionPoints.Count; k++)
                            {
                                if (configFile.productList[i].motioncontrol_Right.motionPoints[k].pointStyle != PointStyle.IOContrlo)
                                {
                                    configFile.productList[i].motioncontrol_Right.motionPoints[k].X = configFile.productList[i].motioncontrol_Right.motionPoints[k].X + offset_value;
                                }
                            }
                        }
                    }

                }
                catch
                {
                    MessageBox.Show("偏移值设置异常");
                }
            }
        }

        private void button81_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否对右工位Y轴位置进行偏移", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    float offset_value = 0;
                    offset_value = Convert.ToSingle(textBox98.Text);
                    if (configFile.productList.Count > 0)
                    {
                        for (int i = 0; i < configFile.productList.Count; i++)
                        {
                            for (int k = 0; k < configFile.productList[i].motioncontrol_Right.motionPoints.Count; k++)
                            {
                                if (configFile.productList[i].motioncontrol_Right.motionPoints[k].pointStyle != PointStyle.IOContrlo)
                                {
                                    configFile.productList[i].motioncontrol_Right.motionPoints[k].Y = configFile.productList[i].motioncontrol_Right.motionPoints[k].Y + offset_value;
                                }
                            }
                        }
                    }

                }
                catch
                {
                    MessageBox.Show("偏移值设置异常");
                }
            }
        }

        private void button82_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否对右工位Z轴位置进行偏移", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    float offset_value = 0;
                    offset_value = Convert.ToSingle(textBox95.Text);
                    if (configFile.productList.Count > 0)
                    {
                        for (int i = 0; i < configFile.productList.Count; i++)
                        {
                            for (int k = 0; k < configFile.productList[i].motioncontrol_Right.motionPoints.Count; k++)
                            {
                                if (configFile.productList[i].motioncontrol_Right.motionPoints[k].pointStyle != PointStyle.IOContrlo)
                                {
                                    configFile.productList[i].motioncontrol_Right.motionPoints[k].Down_Z = configFile.productList[i].motioncontrol_Right.motionPoints[k].Down_Z + offset_value;
                                    configFile.productList[i].motioncontrol_Right.motionPoints[k].Up_Z = configFile.productList[i].motioncontrol_Right.motionPoints[k].Up_Z + offset_value;
                                }
                            }
                        }
                    }

                }
                catch
                {
                    MessageBox.Show("偏移值设置异常");
                }
            }
        }

        private void button83_Click(object sender, EventArgs e)
        {

        }

        private void button84_Click(object sender, EventArgs e)
        {
            homex = 0;
            homey = 0;
            homez = 0;
            if (comboBox11.Text != "")
            {
                try
                {
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].AxisList = new int[] { 0, 1, 4 };
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].Phandle = Phandle;
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[listView1.SelectedItems[0].Index].execute("Left");
                    DialogResult pointoffs = MessageBox.Show("是否到达标记的偏移原点", "提示", MessageBoxButtons.YesNo);
                    if (pointoffs == DialogResult.Yes)
                    {
                        homex = Convert.ToInt16(axisParameter.Axis1Mpos);
                        homey = Convert.ToInt16(axisParameter.Axis2Mpos);
                        homez = Convert.ToInt16(axisParameter.Axis5Mpos);

                    }
                    if (pointoffs == DialogResult.No)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误！" + ex.Message);
                }
            }

        }

        private void button85_Click(object sender, EventArgs e)
        {
            offsx = 0;
            offsy = 0;
            offsz = 0;
            offsx = axisParameter.Axis1Mpos;
            offsy = axisParameter.Axis2Mpos;
            offsz = axisParameter.Axis5Mpos;
            if (comboBox11.Text != "")
            {
                try
                {
                    float[] offs = CompareOffs();
                    DialogResult pointoffs = MessageBox.Show("X坐标偏移：" + offs[0] + "  Y坐标偏移：" + offs[1] + "  Z坐标偏移：" + offs[2], "坐标偏移提示", MessageBoxButtons.YesNo);
                    if (pointoffs == DialogResult.Yes)

                        if (motioncontrol_Left.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < motioncontrol_Left.motionPoints.Count; i++)
                            {
                                if (motioncontrol_Left.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    if (offs[0] > 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X + offs[0];
                                        motioncontrol_Left.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X;
                                        listView1.Items[i].SubItems[3].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X.ToString();
                                    }
                                    if (offs[1] > 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y + offs[1];
                                        motioncontrol_Left.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y;
                                        listView1.Items[i].SubItems[4].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y.ToString();
                                    }
                                    if (offs[0] < 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X + offs[0];
                                        motioncontrol_Left.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X;
                                        listView1.Items[i].SubItems[3].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].X.ToString();
                                    }
                                    if (offs[1] < 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y + offs[1];
                                        motioncontrol_Left.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y;
                                        listView1.Items[i].SubItems[4].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Y.ToString();
                                    }
                                }
                            }

                            string Json_MotionControl_Left = JsonConvert.SerializeObject(configFile.MotionControl_List[NowMotionControl].motioncontrol_Left);
                            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Config") == false)
                            {
                                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\Config");
                            }
                            FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\MotionControl_Left.json", FileMode.Create, FileAccess.Write);
                            StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.Default);
                            streamWriter1.Write(Json_MotionControl_Left);
                            streamWriter1.Close();
                            fileStream1.Close();
                        }
                    if (pointoffs == DialogResult.No)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误！" + ex.Message);
                }
            }


        }
        public float[] CompareOffs()
        {
            float x = 0, y = 0, z = 0;
            float[] offs = new float[3];
            if (offsx > 0 && homex > 0)
            {
                if (offsx > homex) { x = offsx - homex; }
                if (offsx < homex) { x = homex - offsx; x = -x; }
            }
            if (offsx < 0 && homex < 0)
            {
                if (offsx > homex) { x = offsx - homex; }
                if (offsx < homex) { x = homex - offsx; x = -x; }
            }
            if ((offsx > 0 && homex < 0) || (offsx < 0 && homex > 0))
            {
                if (offsx > 0) { x = offsx - homex; }
                if (offsx < 0) { x = offsx - homex; }
            }
            if (offsy > 0 && homey > 0)
            {
                if (offsy > homey) { y = offsy - homey; }
                if (offsy < homey) { y = homey - offsy; }
            }
            if (offsy < 0 && homey < 0)
            {
                if (offsy > homey) { y = offsy - homey; }
                if (offsy < homey) { y = homey - offsy; y = -y; }
            }
            if ((offsy > 0 && homey < 0) || (offsy < 0 && homey > 0))
            {
                if (offsy > 0) { y = offsy - homey; }
                if (offsy < 0) { y = offsy - homey; }
            }
            if (offsz > 0 && homez > 0)
            {
                if (offsz > homez) { z = offsz - homez; }
                if (offsz < homez) { z = homez - offsz; }
            }
            if (offsz < 0 && homez < 0)
            {
                if (offsz > homez) { z = offsz - homez; z = -z; }
                if (offsz < homez) { z = homez - offsz; z = -z; }
            }
            if ((offsz > 0 && homez < 0) || (offsz < 0 && homez > 0))
            {
                if (offsz > 0) { z = offsz - homez; }
                if (offsz < 0) { z = offsz - homez; }
            }
            offs[0] = x;
            offs[1] = y;
            offs[2] = z;
            return offs;
        }

        private void button86_Click(object sender, EventArgs e)
        {
            Form5 form5 = new Form5();
            bool searchok = false;
            form5.ShowDialog();
            if (form5.search == "" || form5.search == null)
            {
                MessageBox.Show("请输入查询型号", "查询提示！");
                return;
            }
            string objsarech = form5.search;
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (objsarech == listBox1.Items[i].ToString())
                {
                    listBox1.SelectedIndex = i;
                    searchok = true;
                }
            }
            if (searchok != true)
            {
                MessageBox.Show("该型号不存在", "查询提示！");
                return;
            }
        }

        private void button88_Click(object sender, EventArgs e)
        {
            float Value = 0;
            if (textBox101.Text != "")
            {
                try
                {
                    Value = Convert.ToSingle(textBox101.Text);
                    if (motioncontrol_Left.motionPoints.Count > 0)
                    {
                        for (int i = 0; i < motioncontrol_Left.motionPoints.Count; i++)
                        {
                            if (motioncontrol_Left.motionPoints[i].pointStyle == PointStyle.KeyTest)
                            {
                                configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints[i].Down_Z = Value;
                                motioncontrol_Left.motionPoints[i].Down_Z = Value;
                                listView1.Items[i].SubItems[6].Text = Value.ToString();
                            }
                        }
                    }
                    MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }

        private void button89_Click(object sender, EventArgs e)
        {
            float Value = 0;
            if (textBox102.Text != "")
            {
                if (comboBox11.Text!="")
                {
                    try
                    {
                        Value = Convert.ToSingle(textBox102.Text);
                        if (motioncontrol_Right.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < motioncontrol_Right.motionPoints.Count; i++)
                            {
                                if (motioncontrol_Right.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Down_Z = Value;
                                    motioncontrol_Right.motionPoints[i].Down_Z = Value;
                                    listView2.Items[i].SubItems[6].Text = Value.ToString();
                                }
                            }
                        }
                        MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("输入的数据不正确", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        /// <summary>
        /// 右工位原点标记
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button91_Click(object sender, EventArgs e)
        {
            homex = 0;
            homey = 0;
            homez = 0;
            if (comboBox11.Text != "")
            {
                try
                {
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].AxisList = new int[] { 2, 3, 5 };
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].Phandle = Phandle;
                    configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[listView2.SelectedItems[0].Index].execute("Right");
                    DialogResult pointoffs = MessageBox.Show("是否到达标记的偏移原点", "提示", MessageBoxButtons.YesNo);
                    if (pointoffs == DialogResult.Yes)
                    {
                        homex = Convert.ToInt16(axisParameter.Axis3Mpos);
                        homey = Convert.ToInt16(axisParameter.Axis4Mpos);
                        homez = Convert.ToInt16(axisParameter.Axis6Mpos);

                    }
                    if (pointoffs == DialogResult.No)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误！" + ex.Message);
                }
            }

        }
        /// <summary>
        /// 右工位坐标偏移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button92_Click(object sender, EventArgs e)
        {
            offsx = 0;
            offsy = 0;
            offsz = 0;
            offsx = axisParameter.Axis3Mpos;
            offsy = axisParameter.Axis4Mpos;
            offsz = axisParameter.Axis6Mpos;
            if (comboBox11.Text != "")
            {
                try
                {
                    float[] offs = CompareOffs();
                    DialogResult pointoffs = MessageBox.Show("X坐标偏移：" + offs[0] + "  Y坐标偏移：" + offs[1] + "  Z坐标偏移：" + offs[2], "坐标偏移提示", MessageBoxButtons.YesNo);
                    if (pointoffs == DialogResult.Yes)

                        if (motioncontrol_Right.motionPoints.Count > 0)
                        {
                            for (int i = 0; i < motioncontrol_Right.motionPoints.Count; i++)
                            {
                                if (motioncontrol_Right.motionPoints[i].pointStyle == PointStyle.KeyTest)
                                {
                                    if (offs[0] > 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X + offs[0];
                                        motioncontrol_Right.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X;
                                        listView2.Items[i].SubItems[3].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X.ToString();
                                    }
                                    if (offs[1] > 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y + offs[1];
                                        motioncontrol_Right.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y;
                                        listView2.Items[i].SubItems[4].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y.ToString();
                                    }
                                    if (offs[0] < 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X + offs[0];
                                        motioncontrol_Right.motionPoints[i].X = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X;
                                        listView2.Items[i].SubItems[3].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].X.ToString();
                                    }
                                    if (offs[1] < 0)
                                    {
                                        configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y + offs[1];
                                        motioncontrol_Right.motionPoints[i].Y = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y;
                                        listView2.Items[i].SubItems[4].Text = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints[i].Y.ToString();
                                    }
                                }
                            }
                            string Json_motioncontrol_Right = JsonConvert.SerializeObject(configFile.MotionControl_List[NowMotionControl].motioncontrol_Right);
                            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Config") == false)
                            {
                                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\Config");
                            }
                            FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Config\motioncontrol_Right.json", FileMode.Create, FileAccess.Write);
                            StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.Default);
                            streamWriter1.Write(Json_motioncontrol_Right);
                            streamWriter1.Close();
                            fileStream1.Close();
                        }
                    if (pointoffs == DialogResult.No)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误！" + ex.Message);
                }
            }

        }

        private void button93_Click(object sender, EventArgs e)
        {
            YKQ_Test test1 = new YKQ_Test();
            test1.configFile = configFile;
            test1.SavaImage = false;
            test1.listBox = listBox6;
            test1.TestStation = TestReslt.TestLeft;
            test1.ykqFeature = ykqFeature;
            test1.NowProductID = NowProductID;
            List<HSmartWindowControl> HwindowsList = new List<HSmartWindowControl>();
            HwindowsList.Add(hSmartWindowControl1);
            HwindowsList.Add(hSmartWindowControl2);
            HwindowsList.Add(hSmartWindowControl3);
            HwindowsList.Add(hSmartWindowControl4);
            test1.HwindowsList = HwindowsList;

            List<Bitmap> ScreenImage = new List<Bitmap>();
            string[] ScreenImageFiles = Directory.GetFiles("D:\\test\\testimage\\Screen\\RN10-L3");
            ScreenImage.Add(new Bitmap(ScreenImageFiles[0]));
            ScreenImage.Add(new Bitmap(ScreenImageFiles[1]));
            ScreenImage.Add(new Bitmap(ScreenImageFiles[2]));
            ScreenImage.Add(new Bitmap(ScreenImageFiles[3]));
            test1.Image_Screen = ScreenImage;

            List<Bitmap> KeyImage = new List<Bitmap>();
            string[] KeyImageFiles = Directory.GetFiles("D:\\test\\testimage\\Key\\RN10-L3");
            KeyImage.Add(new Bitmap(KeyImageFiles[0]));
            KeyImage.Add(new Bitmap(KeyImageFiles[1]));
            KeyImage.Add(new Bitmap(KeyImageFiles[2]));
            KeyImage.Add(new Bitmap(KeyImageFiles[3]));
            test1.Image_Key = KeyImage;
            TestList.Add(test1);




        }

        private void button94_Click(object sender, EventArgs e)
        {
            YKQ_Test test1 = new YKQ_Test();
            test1.configFile = configFile;
            test1.SavaImage = false;
            test1.listBox = listBox6;
            test1.TestStation = TestReslt.TestLeft;
            test1.ykqFeature = ykqFeature;
            test1.NowProductID = NowProductID;
            List<HSmartWindowControl> HwindowsList = new List<HSmartWindowControl>();
            HwindowsList.Add(hSmartWindowControl5);
            HwindowsList.Add(hSmartWindowControl6);
            HwindowsList.Add(hSmartWindowControl7);
            HwindowsList.Add(hSmartWindowControl8);
            test1.HwindowsList = HwindowsList;

            List<Bitmap> ScreenImage = new List<Bitmap>();
            string[] ScreenImageFiles = Directory.GetFiles("D:\\test\\testimage\\Screen\\RN10-L3");
            ScreenImage.Add(new Bitmap(ScreenImageFiles[0]));
            ScreenImage.Add(new Bitmap(ScreenImageFiles[1]));
            ScreenImage.Add(new Bitmap(ScreenImageFiles[2]));
            ScreenImage.Add(new Bitmap(ScreenImageFiles[3]));
            test1.Image_Screen = ScreenImage;

            List<Bitmap> KeyImage = new List<Bitmap>();
            string[] KeyImageFiles = Directory.GetFiles("D:\\test\\testimage\\Key\\RN10-L3");
            KeyImage.Add(new Bitmap(KeyImageFiles[0]));
            KeyImage.Add(new Bitmap(KeyImageFiles[1]));
            KeyImage.Add(new Bitmap(KeyImageFiles[2]));
            KeyImage.Add(new Bitmap(KeyImageFiles[3]));
            test1.Image_Key = KeyImage;
            TestList.Add(test1);
        }

        private void button96_Click(object sender, EventArgs e)
        {
            a = Convert.ToString(textBox103.Text);
            textBox45.Text = a.ToString();
            textBox46.Text = a.ToString();
            textBox47.Text = a.ToString();
            textBox48.Text = a.ToString();
            textBox49.Text = a.ToString();
            textBox50.Text = a.ToString();
            textBox51.Text = a.ToString();
            textBox52.Text = a.ToString();
        }

        private void checkBox7_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox7.Checked == true)
            {
                configFile.Regionfoshan = true;
                return;
            }
            else
            {
                configFile.Regionfoshan = false;
            }
        }

        private void button97_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox104.Text != "")
                {
                    configFile.productList[NowProductID].Key_AreaMin = Convert.ToInt16(textBox104.Text);
                    MessageBox.Show("设置成功");
                }
                else
                {
                    MessageBox.Show("填入的参数为空");
                }
            }
            catch
            {
                MessageBox.Show("输入的参数类型不不正确");
            }
        }
        /// <summary>
        /// 左工位原点设定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button98_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult homepoint1 = MessageBox.Show("左工位原点设定：X轴：" + Convert.ToString(axisParameter.Axis1Mpos) + "  Y轴：" + Convert.ToString(axisParameter.Axis2Mpos) + "  Z轴：" + Convert.ToString(axisParameter.Axis5Mpos), "设定原点提示", MessageBoxButtons.YesNo);
                if (homepoint1 == DialogResult.Yes)
                {
                    label173.Text = Convert.ToString(axisParameter.Axis1Mpos);
                    label175.Text = Convert.ToString(axisParameter.Axis2Mpos);
                    label177.Text = Convert.ToString(axisParameter.Axis5Mpos);
                    configFile.LeftHomeX = axisParameter.Axis1Mpos;
                    configFile.LeftHomeY = axisParameter.Axis2Mpos;
                    configFile.LeftHomeZ = axisParameter.Axis5Mpos;
                    MessageBox.Show("设置成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常" + ex);
            }

        }
        /// <summary>
        /// 右工位原点设定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button99_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult homepoint1 = MessageBox.Show("右工位原点设定：X轴：" + Convert.ToString(axisParameter.Axis3Mpos) + "  Y轴：" + Convert.ToString(axisParameter.Axis4Mpos) + "  Z轴：" + Convert.ToString(axisParameter.Axis6Mpos), "设定原点提示", MessageBoxButtons.YesNo);
                if (homepoint1 == DialogResult.Yes)
                {
                    label182.Text = Convert.ToString(axisParameter.Axis3Mpos);
                    label180.Text = Convert.ToString(axisParameter.Axis4Mpos);
                    label178.Text = Convert.ToString(axisParameter.Axis6Mpos);
                    configFile.RightHomeX = axisParameter.Axis3Mpos;
                    configFile.RightHomeY = axisParameter.Axis4Mpos;
                    configFile.RightHomeZ = axisParameter.Axis6Mpos;

                    MessageBox.Show("设置成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常" + ex);
            }
        }


        private void DisplayNG_Chart(Chart chart)
        {
            List<string> x = new List<string>();
            List<int> y = new List<int>();
            foreach (var i in configFile.Total_Item)
            {
                x.Add(i.Key);
                y.Add(i.Value);
            }

            if (chart.InvokeRequired == true)
            {
                this.BeginInvoke((Action<Chart>)(theChart =>
                {
                    theChart.Series[0].Points.Clear();
                    theChart.Series[0].Label = "#VAL";
                    theChart.Series[0].Name = "不良明细";
                    for (int i = 0; i < x.Count; i++)
                    {

                        theChart.Series[0].Points.AddXY(x[i], y[i]);
                    }
                }), chart);
            }
            else
            {
                chart.Series[0].Points.Clear();
                chart.Series[0].Label = "#VAL";
                chart.Series[0].Name = "不良明细";
                for (int i = 0; i < x.Count; i++)
                {

                    chart.Series[0].Points.AddXY(x[i], y[i]);
                }
            }

            DateTime NowDay = Convert.ToDateTime(configFile.ToDay);
            double productionTime = DateTime.Now.Subtract(NowDay.Add(new TimeSpan(8, 30, 0))).TotalHours;
            if (productionTime > 8)
            {
                List<string> item = new List<string>();
                foreach (var i in configFile.Total_Item)
                {
                    item.Add(i.Key);
                }

                for (int i = 0; i < item.Count; i++)
                {
                    configFile.Total_Item[item[i]] = 0;
                }


                if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Total") == false) Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\Total");
                Day_Total_Item day_Total_Item = new Day_Total_Item();
                day_Total_Item.Total_Day = configFile.ToDay;
                day_Total_Item.Total_Itiem = configFile.Total_Item;

                string Total_str = JsonConvert.SerializeObject(day_Total_Item, Formatting.Indented);
                FileStream fileStream1 = new FileStream(Directory.GetCurrentDirectory() + @"\Total\" + NowDay.ToString("yyyyMMdd") + ".Json", FileMode.Create, FileAccess.Write);
                StreamWriter streamWriter1 = new StreamWriter(fileStream1, Encoding.Default);
                if (Total_str != "")
                {
                    streamWriter1.Write(Total_str);
                }
                streamWriter1.Close();
                fileStream1.Close();
                configFile.ToDay = DateTime.Today.ToString("yyyy-MM-dd");
            }
            else
            {

            }





        }

        private void button94_Click_1(object sender, EventArgs e)
        {
            //初始化统计列表
            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Total") == true)
            {
                string[] TotalList = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\Total");
                if (TotalList.Length > 0)
                {
                    for (int i = 0; i < TotalList.Length; i++)
                    {
                        Day_Total_Item item = new Day_Total_Item();
                        FileStream fileStream1 = new FileStream(TotalList[i], FileMode.Open, FileAccess.Read);
                        StreamReader streamReader1 = new StreamReader(fileStream1, Encoding.Default);
                        String Json_Config = streamReader1.ReadToEnd();
                        streamReader1.Close();
                        fileStream1.Close();
                        item = JsonConvert.DeserializeObject<Day_Total_Item>(Json_Config);
                        listBox8.Items.Add(item);
                    }
                }
            }

        }

        private void button100_Click(object sender, EventArgs e)
        {
            List<string> item = new List<string>();
            foreach (var i in configFile.Total_Item)
            {
                item.Add(i.Key);
            }

            for (int i = 0; i < item.Count; i++)
            {
                configFile.Total_Item[item[i]] = 0;
            }

            MessageBox.Show("设置成功");
        }

        private void button95_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.ShowDialog();
            if (form4.ModelName != "")
            {
                bool exist = false;
                if (configFile.Screen_Model_List.Count > 0)
                {
                    for (int i = 0; i < configFile.Screen_Model_List.Count; i++)
                    {
                        if (configFile.Screen_Model_List[i] == form4.ModelName)
                        {
                            exist = true;
                            break;
                        }
                    }
                }

                if (exist == false)
                {
                    configFile.Screen_Model_List.Add(form4.ModelName);
                    comboBox7.Items.Add(form4.ModelName);
                }
                else
                {
                    MessageBox.Show("该模型已经存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("新增模型异常", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void listBox8_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox8.SelectedIndex > -1)
            {

                //初始化统计列表
                if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Total") == true)
                {
                    string[] TotalList = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\Total");
                    if (TotalList.Length > 0)
                    {
                        for (int i = 0; i < TotalList.Length; i++)
                        {
                            Day_Total_Item item = new Day_Total_Item();
                            FileStream fileStream1 = new FileStream(TotalList[i], FileMode.Open, FileAccess.Read);
                            StreamReader streamReader1 = new StreamReader(fileStream1, Encoding.Default);
                            String Json_Config = streamReader1.ReadToEnd();
                            streamReader1.Close();
                            fileStream1.Close();
                            item = JsonConvert.DeserializeObject<Day_Total_Item>(Json_Config);
                            if (listBox8.SelectedItem.ToString() == item.Total_Day)
                            {

                                List<string> x = new List<string>();
                                List<int> y = new List<int>();
                                foreach (var K in item.Total_Itiem)
                                {
                                    x.Add(K.Key);
                                    y.Add(K.Value);
                                }

                                chart1.Series[0].Points.Clear();
                                chart1.Series[0].Label = "#VAL";
                                chart1.Series[0].Name = "不良明细";
                                for (int J = 0; J < x.Count; J++)
                                {

                                    chart1.Series[0].Points.AddXY(x[J], y[J]);
                                }

                            }
                        }
                    }
                }

            }
        }

        private void button95_Click_1(object sender, EventArgs e)
        {
        }

        private void button101_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否删除选择模型","提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if(dialogResult== DialogResult.OK)
            {
                configFile.Screen_Model_List.Remove(comboBox7.SelectedItem.ToString());
                comboBox7.Items.RemoveAt(comboBox7.SelectedIndex);
                comboBox7.SelectedIndex = -1;
            }
        }

        private void button102_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否删除选择模型", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (dialogResult == DialogResult.OK)
            {
                configFile.Key_Model_List.Remove(comboBox6.SelectedItem.ToString());
                comboBox6.Items.RemoveAt(comboBox6.SelectedIndex);
                comboBox6.SelectedIndex = -1;
            }
        }

        private void button103_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex > -1 && comboBox8.SelectedIndex > -1 && comboBox9.SelectedIndex > -1 && comboBox10.SelectedIndex > -1)
            {
                int ProductID = FindProductID(listBox1.SelectedItem.ToString(), configFile);
                configFile.productList[ProductID].MotionControl_Name = comboBox8.SelectedItem.ToString();
                configFile.productList[ProductID].Screen_Model = comboBox9.SelectedItem.ToString();
                configFile.productList[ProductID].Key_Model = comboBox10.SelectedItem.ToString();
            }
            else
            {
                MessageBox.Show("修改失败！请检查类型是否输入");
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(tabControl1.SelectedIndex==4)
            {
                comboBox8.Items.Clear();
                comboBox9.Items.Clear();
                comboBox10.Items.Clear();
                foreach (KeyValuePair<string,MotionControl_Info> i in configFile.MotionControl_List)
                {
                    comboBox8.Items.Add(i.Key);
                }

                foreach (string j in configFile.Screen_Model_List)
                {
                    comboBox9.Items.Add(j);
                }

                foreach(string k in configFile.Key_Model_List)
                {
                    comboBox10.Items.Add(k);
                }
            }

            if(tabControl1.SelectedIndex == 1)
            {
                comboBox11.Items.Clear();
                foreach (KeyValuePair<string, MotionControl_Info> i in configFile.MotionControl_List)
                {
                    comboBox11.Items.Add(i.Key);
                }
            }
        }

        private void button106_Click(object sender, EventArgs e)
        {
            MotionControl_Info motionControl_Info = new MotionControl_Info();
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Title = "选择导入文件";
            openFileDialog.Filter = "Json(文件)|*.Json";
            openFileDialog.ShowDialog();
            if(openFileDialog.FileName !="")
            {
                FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fileStream, Encoding.Default);
                String JsonTxt = streamReader.ReadToEnd();
                streamReader.Close();
                fileStream.Close();
                motionControl_Info = JsonConvert.DeserializeObject<MotionControl_Info>(JsonTxt);
            }
            try
            {
                configFile.MotionControl_List[comboBox11.SelectedItem.ToString()] = motionControl_Info;
            }
            catch
            {
                MessageBox.Show("导入轨迹失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }

            Refresh_Motion_Left();
            Refresh_Motion_Right();
        }

        private void button104_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.ShowDialog();
            if(form4.ModelName != "")
            {
                MotionControl_Info info = new MotionControl_Info();
                try
                {
                    configFile.MotionControl_List.Add(form4.ModelName, info);
                    comboBox11.Items.Clear();
                    foreach (KeyValuePair<string, MotionControl_Info> i in configFile.MotionControl_List)
                    {
                        comboBox11.Items.Add(i.Key);
                    }
                }
                catch
                {
                    MessageBox.Show("该轨迹已经存在");
                }
            }
        }

        private void comboBox11_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox11.SelectedIndex>-1)
            {
                NowMotionControl = comboBox11.SelectedItem.ToString();
                try
                {
                    if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Left.motionPoints.Count > 0)
                    {
                        motioncontrol_Left = configFile.MotionControl_List[NowMotionControl].motioncontrol_Left;
                        //切换运动轨迹
                        if (listView1.InvokeRequired == false)
                        {
                            listView1.Items.Clear();
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView1);
                        }
                        for (int i = 0; i < motioncontrol_Left.motionPoints.Count; i++)
                        {
                            ListViewItem listViewItem = new ListViewItem();
                            listViewItem.Text = motioncontrol_Left.motionPoints[i].Name;
                            switch (motioncontrol_Left.motionPoints[i].pointStyle)
                            {
                                case PointStyle.IOContrlo:
                                    listViewItem.SubItems.Add("IO控制");
                                    break;
                                case PointStyle.KeyTest:
                                    listViewItem.SubItems.Add("按键测试");
                                    break;
                                case PointStyle.Camera:
                                    listViewItem.SubItems.Add("相机拍照");
                                    break;
                                case PointStyle.KeyTest_IO:
                                    listViewItem.SubItems.Add("按键测试&气缸动作");
                                    break;
                                case PointStyle.Move:
                                    listViewItem.SubItems.Add("移动");
                                    break;
                                case PointStyle.Wait:
                                    listViewItem.SubItems.Add("等待");
                                    break;

                            }
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Code_Value);
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].X.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Y.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Up_Z.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Left.motionPoints[i].Down_Z.ToString());
                            if (listView1.InvokeRequired == false)
                            {
                                listView1.Items.Add(listViewItem);
                            }
                            else
                            {
                                this.Invoke((Action<ListView>)(theView => { theView.Items.Add(listViewItem); }), listView1);
                            }
                        }

                    }
                    else
                    {
                        if (listView1.InvokeRequired == false)
                        {
                            listView1.Items.Clear();
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView1);
                        }
                    }
                    //右工位
                    if (configFile.MotionControl_List[NowMotionControl].motioncontrol_Right.motionPoints.Count > 0)
                    {
                        motioncontrol_Right = configFile.MotionControl_List[NowMotionControl].motioncontrol_Right;
                        if (listView2.InvokeRequired == false)
                        {
                            listView2.Items.Clear();
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView2);
                        }

                        for (int i = 0; i < motioncontrol_Right.motionPoints.Count; i++)
                        {
                            ListViewItem listViewItem = new ListViewItem();
                            listViewItem.Text = motioncontrol_Right.motionPoints[i].Name;
                            switch (motioncontrol_Right.motionPoints[i].pointStyle)
                            {
                                case PointStyle.IOContrlo:
                                    listViewItem.SubItems.Add("IO控制");
                                    break;
                                case PointStyle.KeyTest:
                                    listViewItem.SubItems.Add("按键测试");
                                    break;
                                case PointStyle.Camera:
                                    listViewItem.SubItems.Add("相机拍照");
                                    break;
                                case PointStyle.KeyTest_IO:
                                    listViewItem.SubItems.Add("按键测试&气缸动作");
                                    break;
                                case PointStyle.Move:
                                    listViewItem.SubItems.Add("移动");
                                    break;
                                case PointStyle.Wait:
                                    listViewItem.SubItems.Add("等待");
                                    break;

                            }

                            listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Code_Value);
                            listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].X.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Y.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Up_Z.ToString());
                            listViewItem.SubItems.Add(motioncontrol_Right.motionPoints[i].Down_Z.ToString());

                            if (listView2.InvokeRequired == false)
                            {
                                listView2.Items.Add(listViewItem);
                            }
                            else
                            {
                                this.Invoke((Action<ListView>)(theView => { theView.Items.Add(listViewItem); }), listView2);
                            }
                        }

                    }
                    else
                    {
                        if (listView2.InvokeRequired == false)
                        {
                            listView2.Items.Clear();
                        }
                        else
                        {
                            this.Invoke((Action<ListView>)(theView => { theView.Items.Clear(); }), listView2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    listView1.Items.Clear();
                    listView2.Items.Clear();
                }
            }
        }

        private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox7.SelectedIndex > -1)
            {
                NowScreenModel = comboBox7.SelectedItem.ToString();
                listBox2.Items.Clear();
                try
                {
                    string[] ScreenFearure = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Screen\" + NowScreenModel + @"\ModelID");
                    if (ScreenFearure.Length > 0)
                    {
                        for (int i = 0; i < ScreenFearure.Length; i++)
                        {
                            listBox2.Items.Add("特征:" + (i + 1));
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("遍历屏幕模板文件异常");
                }
            }
        }

        private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox6.SelectedIndex > -1)
            {
                NowKeyModel = comboBox6.SelectedItem.ToString();
                listBox3.Items.Clear();
                try
                {
                    string[] ScreenFearure = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\ProductModel\Key\" + NowKeyModel + @"\ModelID_Key"); 
                    if (ScreenFearure.Length > 0)
                    {
                        for (int i = 0; i < ScreenFearure.Length; i++)
                        {
                            listBox3.Items.Add("特征:" + (i + 1));
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("遍历按键模板文件异常");
                }
            }
        }

        private void button105_Click(object sender, EventArgs e)
        {
            try
            {
                configFile.MotionControl_List.Remove(comboBox11.SelectedItem.ToString());
                comboBox11.Items.Remove(comboBox11.SelectedItem.ToString());
                MessageBox.Show("删除失败", "提示");
            }
            catch
            {
                MessageBox.Show("删除成功","提示");
            }
        }

        private void button107_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog1.Title = "保存文件路径";
            saveFileDialog1.Filter = "Json文档|*.Json";
            saveFileDialog1.ShowDialog();
            MotionControl_Info control_Info = configFile.MotionControl_List[NowMotionControl];
            string Json_txt = JsonConvert.SerializeObject(control_Info,Formatting.Indented);
            FileStream fileStream = new FileStream(saveFileDialog1.FileName, FileMode.Create);
            StreamWriter streamWriter = new StreamWriter(fileStream,Encoding.UTF8);
            streamWriter.Write(Json_txt);
            streamWriter.Close();
            fileStream.Close();
            
        }
    }
}

 
